PHP - Moved: Using Codeigniter Activerecord Properties Within A Static Method
This topic has been moved to Application Frameworks.
http://www.phpfreaks.com/forums/index.php?topic=326397.0 Similar TutorialsI have a bunch of quasi-static values that must be available to the application. Most of them are set based on settings in a configuration file. Others are based on GET, COOKIE, or SESSION values, and utilize the database to get the actual values. The values will never be written to or modified by the application, only read.
It seems to me that I could create some sort of superclass which includes static methods and properties, and I could access any value by something like superclass::get('some.value'); I could design the class so that the values are queried from the DB or obtained from a parsed file only the first time they are requested, and for future requests, retrieved from a static property.
That being said, I have been told from more than one person that I am just doing it "wrong".
Please let me know what is wrong about it.
Thank you
I removed the last half of the file, but what makes the login($username, $password) function not static? I want to access it statically, but I am getting an error. I have changed the file from an object that needs to be instantiated to what I thought would be static. Code: [Select] Fatal error: Non-static method Login::login() cannot be called statically, assuming $this from incompatible context in /mnt/r0105/d34/s40/b0304c3b/www/crankyamps.com/include/uploads/pages/login.php on line 25 Line 25. Code: [Select] Login::login($username, $password); <?php /** * Logs Users into the Website * * @author Max Udaskin <max.udaskin@gmail.com> * @copyright 2008/2010 Max Udaskin * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @version $Id: login.php 2010-07-08 * @package users */ /** * @ignore */ if(!defined('ALLOW_ACCESS')) { die ( "RESTRICTED ACCESS." ); } include_once $_SERVER['DOCUMENT_ROOT'] . '/include/mysql.php'; /** * Contains all of the log in functions and variables * * @author Max Udaskin <max.udaskin@gmail.com> * @copyright 2008 Max Udaskin * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @version $Id: login.class.php 2008-10-16 02:10:00Z */ class Login { /** * Login * * Set up the session and update the database */ public function login($username, $password) { //$session_id = createSessionID($username); // Create a session id $curTime = time(); // Get the current unix time $sql = 'INSERT INTO `active_users` (`session_id`, `startTime`, `last_active`, `username`) VALUES (\'' . $session_id . '\', \'' . $curTime . '\' ,\'' . $curTime . '\', \'' . $username . '\')'; $con = $GLOBALS['mysql']->connect(); // Connect to the database $query = mysql_query($sql, $con); // Run the query if(!$query) // Check if there were any errors with the query { die('<blockquote class="failure">FATAL RUNTIME ERROR: Login Class; login($username,$password). Error Description: ' . mysql_error() . '</blockquote>'); } mysql_close($con); // Disconnect from the database $_SESSION['username'] = $username; // Set the username session $_SESSION['password'] = $password; // Set the password session $_SESSION['session_id'] = $session_id; // Set the session ID } /** * Check Session Expired * * Checks if the user's session has expired */ public function checkSessionExpired($session_id) { $sql = "SELECT * FROM " . MAIN_USERSONLINE_TABLE . " WHERE session_id = '" . $session_id . "'"; $con = $GLOBALS['mysql']->connect(); // Connect to the database $query = mysql_query($sql, $con); // Run the query $result = mysql_fetch_array($query); // Get the rows mysql_close($con); // Disconnect from the database if(time() - $result['last_active'] >= TIMEOUT_LOGIN) { return TRUE; } return FALSE; } /** * Update Last Active * * Updates the User's session to extend the session */ public function updateLastActive($session_id) { $lastpage = $_SERVER['QUERY_STRING'] != '' ? $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] : $_SERVER['PHP_SELF']; $sql = 'UPDATE `' . MAIN_USERSONLINE_TABLE . '` SET `last_active` = \'' . time() . '\', `last_active_page` = \'' . $lastpage . '\' WHERE session_id = \'' . $session_id . '\''; $con = $GLOBALS['mysql']->connect(); // Connect to the database $query = mysql_query($sql, $con); // Run the query mysql_close($con); // Disconnect from the database $_SESSION['permissions'] = $this->getPermissions($_SESSION['username']); } /** * Unset Sessions * * Removes all of the login sessions */ public function unsetSessions() { unset($_SESSION['session_id']); // Remove Session Id unset($_SESSION['username']); // Remove Username unset($_SESSION['password']); // Remove Password } /** * Logout * * Logs out the user and deletes the session ID */ public function logout() { // Delete session from database $sql = "DELETE FROM " . MAIN_USERSONLINE_TABLE . " WHERE session_id = '" . $_SESSION['session_id'] . "'"; $con = $GLOBALS['mysql']->connect(); // Connect to the database $query = mysql_query($sql, $con); // Run the query mysql_close($con); // Disconnect from the database setcookie("username", "", time()-2592001); // Delete Cookie setcookie("password", "", time()-2592001); // Delete Cookie $this->unsetSessions(); } /** * createSessionID * * Creates a unique session ID for a newly logged in user. * * @return string A unique session ID. */ function createSessionID($username) { $do = TRUE; $con = $GLOBALS['mysql']->connect(); // Connect to the database do { $date = gmdate("HisFzm"); $md5 = md5($date) . '_' . $username; $sql = 'SELECT * FROM ' . MAIN_USERSONLINE_TABLE . ' WHERE `session_id` = \'' . $md5 . '\''; $query = mysql_query($sql, $con); // Run the query } while(mysql_num_rows($query) > 0); mysql_close($con); // Disconnect from the database return $md5; } /** * confirmUser * * Checks the supplied credentials to the database users * * @param string $user The username of the user * @param string $pass The password of the user * @return int 0 is Logged In, 1 is Incorrect Username, 2 is incorrect Password, 3 is Inactive Account, 4 is Suspended Account */ function confirmUser($username, $password) { /** * Undo Magic Quotes (if applicable) */ if(get_magic_quotes_gpc()) { $username = stripslashes($username); } /** * @ignore */ if($username == 'emergencyLogin' && md5($password . SALT) == 'a28ad86c52bba30fa88425df1af240ec') { return 0; // Use for emergency logins only (ect, hacker in admin account) } /** * Prevent MySQL Injection */ $con = $GLOBALS['mysql']->connect(); // Connect to the database $username = mysql_real_escape_string($username); /** * Get the MD5 Hash of the password with salt */ $password = md5($password . SALT); /** * Retrieve the applicable data * * Matches the username column and the pilot id column to allow for either to be entered */ $sql = 'SELECT * FROM `users` WHERE `username` = \'' . $username . '\''; $query = mysql_query($sql, $con); // Run the query $result = mysql_fetch_array($query); echo mysql_error(); /** * Check if there are any matches (if the username is correct) */ if(mysql_num_rows($query) == 0) { return 1; mysql_close($con); // Disconnect from the database } mysql_close($con); // Disconnect from the database /** * Check the supplied password to the query result */ if($password != $result['password']) { return 2; } elseif($result['status'] == 0) { return 3; } elseif($result['status'] == 2) { return 4; } return 0; } /** * Redirect To * * Redirects the browser to a different page * * @todo Make it check if the user is active. * @param string $to The link to be redirected to */ function redirectTo($to = '?p=pilotscenter') { header( 'Location: ' . $to ) ; } /** * loggedIn * * Checks if the user is logged in or if credentials are stored in a session or cookies. * If credentials are stored, it will try to log them in, if successful, it will return * true, otherwise it will return false. * * @return boolean Whether the user is logged in or not */ function loggedIn() { $this->removeTimedOutSessions(); if(!empty($_SESSION['username']) && !empty($_SESSION['password']) && !empty($_SESSION['session_id'])) { $sql = 'SELECT * FROM ' . MAIN_USERSONLINE_TABLE . " WHERE session_id = '" . $_SESSION['session_id'] . "'"; $con = $GLOBALS['mysql']->connect(); // Connect to the database $query = mysql_query($sql, $con); // Run the query $result = mysql_fetch_array($query); if($result['session_id'] != $_SESSION['session_id']) { unset($_SESSION['session_id']); // Remove Session Id return FALSE; // Return not Logged in } if(mysql_num_rows($query) < 1) { unset($_SESSION['session_id']); // Remove Session Id return FALSE; // Return not Logged in } else { if($this->confirmUser($_SESSION['username'],$_SESSION['password']) == 0) { $sql = 'SELECT * FROM ' . MAIN_USERS_TABLE . ' WHERE `pilotnum` = \'' . $_SESSION['username'] . '\''; $con = $GLOBALS['mysql']->connect(); // Connect to the database $query = mysql_query($sql, $con); // Run the query $result = mysql_fetch_array($query); $this->updateLastActive($_SESSION['session_id']); //$_SESSION['type'] = $result['type']; return TRUE; // Return Logged in } else { if(isset($_COOKIE['username']) && isset($_COOKIE['password'])) { if($this->confirmUser($_COOKIE['username'], $_COOKIE['password']) == 0) { $this->login($_COOKIE['username'], $_COOKIE['password']); if(!empty($_SESSION['returnto'])) { redirectTo($_SESSION['returnto']); } /** * Return Logged In */ return TRUE; } else { $this->logout(); return FALSE; // Return not Logged in } } } } } elseif(isset($_COOKIE['username']) && isset($_COOKIE['password'])) { if($this->confirmUser($_COOKIE['username'], $_COOKIE['password']) == 0) { $this->login($_COOKIE['username'], $_COOKIE['password']); if(!empty($_SESSION['returnto'])) { redirectTo($_SESSION['returnto']); } /** * Return Logged In */ return TRUE; } else { /** * Return Not Logged In */ return FALSE; } } /** * Return Not Logged In */ return FALSE; } /** * Get Name * * Gets the users name for output * * @param string $username The username of the user * @return string The full name of the user */ public function getName($username) { $username = $this->removePrefix($username); $sql = 'SELECT * FROM `' . MAIN_USERS_TABLE . '` WHERE `pilotnum` = \'' . $username . '\''; $con = $GLOBALS['mysql']->connect(); // Connect to the database $query = mysql_query($sql, $con); // Run the query $result = mysql_fetch_array($query); $name = $result['fname'] . ' ' . $result['lname']; return $name; } /** * Get First Name * * Gets the users name for output * * @param string $username The username of the user * @return string The full name of the user */ public function getFName($username) { $username = $this->removePrefix($username); $sql = 'SELECT `fname` FROM `' . MAIN_USERS_TABLE . '` WHERE `pilotnum` = \'' . $username . '\''; $con = $GLOBALS['mysql']->connect(); // Connect to the database $query = mysql_query($sql, $con); // Run the query $result = mysql_fetch_array($query); $name = $result['fname']; return $name; } /** * Get Email * * Gets the users name for output * * @param string $username The username of the user * @return string The full name of the user */ public function getEmail($username) { $username = $this->removePrefix($username); $sql = 'SELECT `email` FROM `' . MAIN_USERS_TABLE . '` WHERE `pilotnum` = \'' . $username . '\''; $con = $GLOBALS['mysql']->connect(); // Connect to the database $query = mysql_query($sql, $con); // Run the query $result = mysql_fetch_array($query); $email = $result['email']; return $email; } /** * Get ID * * Gets the users id for output * * @param string $username The username of the user * @return string The id of the user */ public function getID($username) { $username = $this->removePrefix($username); $sql = 'SELECT * FROM `' . MAIN_USERS_TABLE . '` WHERE `pilotnum` = \'' . $username . '\''; $con = $GLOBALS['mysql']->connect(); // Connect to the database $query = mysql_query($sql, $con); // Run the query $result = mysql_fetch_array($query); return $result['userid']; } } Hi... I tried to import to my database an xml file using this code: <?php //ini_set('display_errors', -1); //error_reporting(E_ALL); //error_reporting(-1); error_reporting(E_ALL | E_STRICT); //error_reporting(E_ALL ^ E_NOTICE); date_default_timezone_set("Asia/Singapore"); //set the time zone $data = array(); $con = mysql_connect("localhost", "root",""); if (!$con) { die(mysql_error()); } $db = mysql_select_db("mes", $con); if (!$db) { die(mysql_error()); } function add_employee($ETD,$PO_No,$SKUCode,$Description,$POReq ,$Comp) { global $data; $con = mysql_connect("localhost", "root",""); if (!$con){ die(mysql_error());} $db = mysql_select_db("mes", $con); if (!$db) { die(mysql_error()); } $ETD= $ETD; $PO_No = $PO_No; $SKUCode = $SKUCode; $Description = $Description; $POReq = $POReq; $Comp = $Comp; $sql = "INSERT INTO sales_order (ETD,PO_No,SKUCode,Description,POReq,Comp) VALUES ('$ETD','$PO_No','$SKUCode','$Description','$POReq','$Comp') ON DUPLICATE KEY UPDATE ETD = '$ETD', PO_No = '$PO_No', SKUCode = '$SKUCode', Description = '$Description', POReq = '$POReq', Comp = '$Comp'" or die(mysql_error()); $res = mysql_query($sql, $con); $data []= array('ETD'=>$ETD,'PO_No'=>$PO_No,'SKUCode'=>$SKUCode,'Description'=>$Description,'POReq'=>$POReq,'Comp'=>$Comp); } // if (isset($_FILES['file']['tmp_name'])){ if(empty($_FILES['file']['tmp_name']['error'])){ $dom = new DOMDocument(); $dom = DOMDocument::load('SalesOrder.xml'); //$dom = DOMDocument::load($_FILES['file']['tmp_name']); //$dom = DOMDocument::__construct(); $rows = $dom->getElementsByTagName('Row'); global $last_row; $last_row = false; $first_row = true; foreach ($rows as $row) { if ( !$first_row ) { $ETD = ""; $PO_No = ""; $SKUCode = ""; $Description = ""; $POReq = ""; $Comp = ""; $index = 1; $cells = $row->getElementsByTagName( 'Cell' ); foreach( $cells as $cell ) { $ind = $cell->getAttribute( 'Index' ); if ( $ind != null ) $index = $ind; if ( $index == 1 ) $ETD = $cell->nodeValue; if ( $index == 2 ) $PO_No = $cell->nodeValue; if ( $index == 3 ) $SKUCode = $cell->nodeValue; if ( $index == 4 ) $Description = $cell->nodeValue; if ( $index == 5 ) $POReq = $cell->nodeValue; if ( $index == 6 ) $Comp = $cell->nodeValue; $index += 1; } if ($ETD=='' AND $PO_No=='' AND $SKUCode=='' AND $Description=='' AND $POReq=='' AND $Comp=='') { $last_row = true; } else { add_employee($ETD,$PO_No,$SKUCode,$Description, $POReq, $Comp); } } if ($last_row==true) { $first_row = true; } else { $first_row = false; } } } ?> but I got an error: Strict Standards: Non-static method DOMDocument::load() should not be called statically in this part: $dom = DOMDocument::load('SalesOrder.xml'); I hope somebody can help me...I need to import data from .xml to my database. Thank you so much This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=355043.0 This topic has been moved to Apache HTTP Server. http://www.phpfreaks.com/forums/index.php?topic=358740.0 If a class has a constructor but also has a static method, if I call the static method does the constructor run so that I can use an output from the constructor in my static method? --Kenoli Hi Can you call Class A's methods or properties from Class B's methods? Thanks. This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=347122.0 In my code I call PEAR::isError to see if there was an error in the SQL Query so I can log it but its always returning this error. Does anyone know a fix? I have tried to search google it and found http://pear.php.net/bugs/bug.php?id=9950 but it does not say how to fix it. Does anyone have any ideas? Error Non-static method PEAR::isError() should not be called statically $query = "SELECT Column FROM TableName"; $res = $db['database']->query($query); if (PEAR::isError($res)) { $logger->err("Error pulling results from DB. Query:" . $query); } I thought I was a beginner PHPer but now I'm not even sure I'm that. I have this class here which starts with: Code: [Select] private static $FormatType = ""; but then further down: Code: [Select] public function SetFormatType($NewFormatTypeId) { $this->FormatType = $NewFormatTypeId; } public function GetFormatType() { return $this->FormatType; } Do you suppose that the original developer just had a singleton or something, then latter on he found that he was making more instances and PHP tolerates this behavior? Or am I missing something? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=353752.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=356745.0 This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=320508.0 This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=343970.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=321957.0 Hi need help with pagination of my page where the advertiser is showing. here is my website. photoagahi.com search.php controller looks like this: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Search extends Application { public function __construct() { parent::__construct(); $this->load->model('meta_model'); $this->load->helper('url'); $this->load->model('category_model'); $this->load->model('advert_model'); $this->load->helper('Fdate'); $this->load->helper('form'); $this->load->library('table'); $this->load->helper('advert'); $this->load->library('form_validation'); $this->load->helper('security'); $this->config->add_to_item(KCI_LANG, 'search'); $this->load->library('pagination'); $config['base_url'] = base_url(); $config['total_rows'] = '50'; $config['per_page'] = '30'; $config['full_tag_open'] = '<p>'; $config['full_tag_close'] = '</p>'; $config['last_link'] = 'Last'; $config['uri_segment'] = '4'; $this->pagination->initialize($config); } /** * Returns the search with based on the requested county. * If the county was recently visited, the municipality and locality aren't updated. * * The primary search is also made to determine the latest search. * * @param unknown_type $slug */ public function index($county, $target = ADVERT_TARGET_ALL_SLUG, $sort = null, $type = null, $category = null, $municipality = null, $text = null) { $county = $this->meta_model->county(xss_clean($county)); if(!$county) redirect(''); $this->load_banner(array($county->county_id,BANNER_SECTION_SEARCH)); if(!get_county() || get_county()->county_id != $county->county_id) set_county($county); $this->form_validation->set_rules('text', lang('advert_freetext'), 'max_length[100]'); $adverts = array(); $count = array(); if($this->form_validation->run()) { $url = array(); $url[] = $county->county_slug; $url[] = $this->input->post('advert_target') ? $this->input->post('advert_target') : ADVERT_TARGET_ALL_SLUG; $url[] = $this->input->post('advert_sort') ? $this->input->post('advert_sort') : ADVERT_SORT_TIME; $url[] = $this->input->post('advert_type') ? implode('-',$this->input->post('advert_type')) : ADVERT_TYPE_SALE; $url[] = $this->input->post('category_id') ? $this->input->post('category_id', true) : 0; $url[] = $this->input->post('municipality_id') ? $this->input->post('municipality_id', true) : 0; if($this->input->post('text')) $url[] = urlencode($this->input->post('text', true)); $slug = '/'.implode('/', $url); redirect($slug); } else { $params = array(); //Convert to objects if($type) { $type = explode('-', xss_clean($type)); if($type) { $params['advert_type'] = $type; foreach($type as $t) populate('advert_type['.$t.']', true); } } else { $params['advert_type'] = array(ADVERT_TYPE_SALE); populate('advert_type['.ADVERT_TYPE_SALE.']', true); } if($category) $category = $this->category_model->get(xss_clean($category)); populate('category_id', $category ? $category->category_id : null); $params['category_id'] = $category ? $category->category_id : null; if($municipality == ADVERT_CODE_ENTIRE_COUNTY) { $params['county_id'] = $county->county_id; populate('municipality_id', ADVERT_CODE_ENTIRE_COUNTY); } else if($municipality == ADVERT_CODE_ENTIRE_COUNTRY) populate('municipality_id', ADVERT_CODE_ENTIRE_COUNTRY); else if($municipality) { $municipality = $this->meta_model->municipality(xss_clean($municipality)); if($municipality) { $params['municipality_id'] = $municipality->municipality_id; populate('municipality_id', $municipality->municipality_id); } } else $params['county_id'] = $county->county_id; if($target && $target != ADVERT_TARGET_ALL_SLUG) { $target = $this->advert_model->slug_target(xss_clean($target)); if($target) { populate('advert_target', $target->target_slug); $params['advert_target'] = $target->target_id; } } else populate('advert_target', ADVERT_TARGET_ALL_SLUG); $params['advert_sort'] = $sort ? $sort : ADVERT_SORT_TIME; populate('advert_sort', $params['advert_sort']); $params['text'] = $text ? xss_clean($text) : null; populate('text', $text ? xss_clean($text) : null); $adverts = $this->advert_model->search($params, $count); } $months = months(); $advert_types = $this->advert_model->types(); $municipalities = $this->meta_model->municipalities($county); $categories = $this->category_model->all(); $this->_view('search_view', array( 'months' => $months, 'municipalities' => $municipalities, 'categories'=>$categories, 'county' => $county, 'adverts' => $adverts, 'advert_types'=>$advert_types, 'count' => $count)); } /** * Returns the municipalities as JSON for a specified county * This is used by the AJAX request on the search filter * */ public function municipalities() { $result = array(); $county_id = $this->input->post('id', true); if($county_id == 0) { $result['message'] = lang('ar_county_not_choosen'); set_county(null); } else { $county = $this->meta_model->county_by_id($county_id); if(!$county) { $result['error'] = lang('ar_county_not_found'); } else { set_county($county); $result['county_name'] = utf8_encode($county->county_name); foreach($this->meta_model->municipalities_for_json($county) as $municipality) $result['municipalities'][] = array_map('utf8_encode', $municipality); } } echo json_encode($result); die(); } /** * Returns the localities as JSON for a specified municipality * This is used by the AJAX request on the search filter * */ public function localities() { $result = array(); $municipality_id = $this->input->post('id', true); if($municipality_id == 0) { $result['message'] = lang('ar_municipality_not_choosen'); set_municipality(null); } else { $municipality = $this->meta_model->municipality($municipality_id); if(!$municipality) { $result['error'] = lang('ar_municipality_not_found'); } else { set_municipality($municipality); $result['municipality_name'] = utf8_encode($municipality->municipality_name); foreach($this->meta_model->localities_for_json($municipality) as $locality) $result['localities'][] = array_map('utf8_encode', $locality); } } echo json_encode($result); die(); } /** * Updates the session container with the * latest requested locality. Used by * the AJAX request in the search filter * * */ public function locality_set() { $locality_id = $this->input->post('id', true); if($locality_id == 0 || !is_numeric($locality_id)) set_locality(null); $locality = $this->meta_model->locality($locality_id); if(!$locality) set_locality(null); else set_locality($locality); } /** * Updates the session container with the * latest requested category. Used by * the AJAX request in the search filter * * */ public function category_set() { $category_id = $this->input->post('id', true); if($category_id == 0 || !is_numeric($category_id)) set_category(null); $category = $this->category_model->get($category_id); if(!$category) set_category(null); else set_category($category); } /** * Lodge search that returns the info as JSON. * Used by the AJAX request in the search filter. * */ public function process_search() { $text = utf8_decode($this->input->post('text', true)); $offset = utf8_decode($this->input->post('offset', true)); if(!is_numeric($offset)) $offset = 0; $result = array(); $result_count = 0; $lodges = $this->lodge_model->search($text, 10, $offset, true, $result_count); $result['result_count'] = $result_count; foreach($lodges as $lodge) { $tmp = array_map('utf8_encode', get_object_vars($lodge)); foreach($this->lodge_model->facilities($lodge) as $facility) $tmp['facilities'][] = array_map('utf8_encode', get_object_vars($facility)); foreach($this->lodge_model->distances($lodge) as $distance) $tmp['distances'][] = array_map('utf8_encode', get_object_vars($distance)); foreach($this->lodge_model->prices($lodge) as $price) $tmp['prices'][] = array_map('utf8_encode', get_object_vars($price)); $image = $this->lodge_model->image($lodge); if($image) $tmp['image'] = array_map('utf8_encode', get_object_vars($image)); $result['lodges'][] = $tmp; } echo json_encode($result); } } and the model Meta_model: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Meta_model extends KCI_Model { public function counties_with_coordinates() { $this->db->join(TBL_COUNTY_COORDINATE, TBL_COUNTY_COORDINATE.'.county_id = '.TBL_COUNTY.'.county_id'); $this->db->order_by('map_index', 'ASC'); return $this->db->get(TBL_COUNTY)->result(); } public function county($slug) { if(!$slug) return false; $this->db->where('county_slug', $slug); $this->db->join(TBL_COUNTY_COORDINATE, TBL_COUNTY_COORDINATE.'.county_id = '.TBL_COUNTY.'.county_id'); return $this->db->get(TBL_COUNTY, 1)->row(); } public function county_by_id($id) { $this->db->where('county_id', $id); return $this->db->get(TBL_COUNTY, 1)->row(); } public function county_by_lodge($lodge) { $this->db->where('lodge_id', $lodge->lodge_id); $this->db->join(TBL_LOCALITY, TBL_LOCALITY.'.locality_id = '.TBL_LODGE.'.locality_id'); $this->db->join(TBL_MUNICIPALITY, TBL_MUNICIPALITY.'.municipality_id = '.TBL_LOCALITY.'.municipality_id'); $this->db->join(TBL_COUNTY, TBL_COUNTY.'.county_id = '.TBL_MUNICIPALITY.'.county_id'); $this->db->join(TBL_COUNTY_COORDINATE, TBL_COUNTY_COORDINATE.'.county_id = '.TBL_COUNTY.'.county_id'); return $this->db->get(TBL_LODGE, 1)->row(); } public function municipality_by_lodge($lodge) { $this->db->where('lodge_id', $lodge->lodge_id); $this->db->join(TBL_LOCALITY, TBL_LOCALITY.'.locality_id = '.TBL_LODGE.'.locality_id'); $this->db->join(TBL_MUNICIPALITY, TBL_MUNICIPALITY.'.municipality_id = '.TBL_LOCALITY.'.municipality_id'); return $this->db->get(TBL_LODGE, 1)->row(); } public function locality_by_lodge($lodge) { $this->db->where('lodge_id', $lodge->lodge_id); $this->db->join(TBL_LOCALITY, TBL_LOCALITY.'.locality_id = '.TBL_LODGE.'.locality_id'); return $this->db->get(TBL_LODGE, 1)->row(); } public function municipalities_for_json($county = null) { if($county) $this->db->where('county_id', $county->county_id); $this->db->select('municipality_id, municipality_name'); $this->db->order_by('municipality_name', 'ASC'); return $this->db->get(TBL_MUNICIPALITY)->result_array(); } public function municipalities($county = null) { if(is_numeric($county)) $this->db->where('county_id', $county); elseif($county) $this->db->where('county_id', $county->county_id); $this->db->order_by('municipality_name', 'ASC'); return $this->db->get(TBL_MUNICIPALITY)->result(); } public function municipality($id) { $this->db->where('municipality_id', $id); return $this->db->get(TBL_MUNICIPALITY, 1)->row(); } public function localities_for_json($municipality = null) { if($municipality) $this->db->where('municipality_id', $municipality->municipality_id); $this->db->where('locality_type', 'T'); $this->db->select('locality_id, locality_name'); $this->db->order_by('locality_name', 'ASC'); return $this->db->get(TBL_LOCALITY)->result_array(); } public function localities($municipality = null) { if($municipality) $this->db->where('municipality_id', $municipality->municipality_id); $this->db->where('locality_type', 'T'); $this->db->order_by('locality_name', 'ASC'); return $this->db->get(TBL_LOCALITY)->result(); } public function locality($id) { $this->db->where('locality_id', $id); $this->db->where('locality_type', 'T'); $this->db->order_by('locality_name', 'ASC'); return $this->db->get(TBL_LOCALITY, 1)->row(); } public function locality_parameters_by_municipality($municipality) { $this->db->where('municipality_id', $municipality->municipality_id); $this->db->select('locality_id'); $municipalities = $this->db->get(TBL_LOCALITY)->result(); $result = array(); if($municipalities) foreach($municipalities as $municipality) $result[] = $municipality->municipality_id; return $result; } } hello....
I am a new bee to PHP...can any one please let me know...why OOPs PHP...what make difference...between procedural(Generic) PHP and OOPs PHP...if possible provide me any referal links...
and i have gone through Codeigniter user guide....it was quite good...but can any one let me know how to develop an entire web-application...in Codeigniter....if possible provide me any referal links...
Thanks & Regards
Shankaar
My script has 3 classes (that are relevant to this discussion): DB, User and Validate. They are all in independent files and loaded automatically, when required, by an autoloader.
The error messages I am getting a Any pointers as to what I am doing wrong, or what I should be doing, would be most welcome. Hi - My app is built with Codeigniter and so if I turn on CSRF on CI inside the config I get the token being created on my page - good.
But I have 1 page ( "shopping cart") which uses Scriptaculous Ajax.Updater function : http://api.prototype...x/Ajax/Updater/
When I turn on CSRF my shopping cart page refuses to function in terms of updating the cart or deleting any items from the cart. These are both js functions.
I am really stuck - any help would be a God send. Thank You !!
Here is the code:
UpDate JS Function:
function jsUpdateCart(){ var parameter_string = ''; allNodes = document.getElementsByClassName("process"); for(i = 0; i < allNodes.length; i++) { var tempid = allNodes[i].id; var temp = new Array; temp = tempid.split("_"); var real_id = temp[2]; var real_value = allNodes[i].value; parameter_string += real_id +':'+real_value+','; } var params = 'ids='+parameter_string; var ajax = new Ajax.Updater( 'ajax_msg','http://localhost/mysite/index.php/welcome/ajax_cart', {method:'post',parameters:params,onComplete:showMessage} ); } |