Jump to content

c_pattle

Members
  • Posts

    295
  • Joined

  • Last visited

Posts posted by c_pattle

  1. Thanks.  I have autoloaded the session and I have the following code

     

    $this->ci =& get_instance();
    $this->ci->load->library('session');
    

     

    but I still get the error

     

    Call to a member function userdata() on a non-object

     

    Is there something I'm doing wrong?

  2. I have a library called "Layout" which controls the main layout for my site.  In my header method I have this code that checks to see if the "loggedin" variable is set and then loads a view depending on the outcome. 

     

    $loggedin = 0;
            if($loggedin)
            {
                $aData['myAccount'] = '<div class="my_account">';
                $aData['myAccount'] .= $this->load->view('account/myaccount', '', true);
                $aData['myAccount'] .= '</div>';
            }
            else
            {
                $aData['myAccount'] = '<div class="login_or_register">';
                //Assign the login view to the $aData array for display
                $aData['myAccount'] .= $this->load->view('account/login', '', true);
                $aData['myAccount'] .= '</div>';
            }
    

     

    This works but what I want to do is to check if a session variable is set.  However it's not possible to load the session library from within another library.  Is there a way round this problem?

     

    Thanks

  3. I have a form that when submitted goes to "products/search/"

     

    This is the method that it directs too. 

     

        function search($searchCat = NULL, $searchString = NULL)
        {
            if($this->input->post('searchSubmit'))
            {
                $searchCat = $this->input->post('searchCat');
                $searchString = $this->input->post('searchString');
            }
            
             //Get the base URL and assign it to a variable
            $aData['base_url'] = base_url();
            
            //Run the getProductsBySearch function in the product model and pass two parameters
            //This returns the search results
            $aData['query'] = $this->ProductModel->GetProductsBySearch($searchCat, $searchString);
            
            //Run the getBestSellers function in the product model
            //This returns the top 3 best selling products
            $aData['bestsellers'] = $this->ProductModel->getBestSellers();
            
            //Pass the best sellers data to the best sellers view and save it in a variable
            $aData['rightSidebar'] = $this->load->view('products/bestsellers', $aData, true);
           
            //Get breadcrumb trail and assign it to a variables
            $aData['breadcrumbs'] = create_breadcrumb();
            
            //Pass the data to the left sidebar view and save it in a variable
            $aData['leftSidebar'] = $this->load->view('products/leftsidebar', $aData, true);
            
            //Load the cart library
            //$this->load->library('cart');
            
            //Get the contents, total amount and total items of the cart
            $aData['cart'] = $this->cart->contents();
            $aData['cart_total'] = $this->cart->total();
            $aData['total_items'] = $this->cart->total_items();
            
            //Load the layout library
            $this->load->library('layout');  
            
            //Get the header and footer and save them in variables
            $aData['header'] = $this->layout->pageHeader($aData);
            $aData['footer'] = $this->layout->pageFooter();
            
            //If more than one row is returned load multiple product view otherwise load single view
            if ($aData['query']->num_rows() > 1)
            {
                $aData['content'] = $this->load->view('products/products_layout', $aData, true);
            } 
            else
            {
                $aData['content'] = $this->load->view('products/product_layout', $aData, true);
            }
            
            //Load the three column layout view
            $this->load->view('layout/main/three_col', $aData);
            
        }
    

     

    Then in my views file I have the following lines. 

     

    $route['products/search/'] = "products/search/";
    $route['products/search/(:any)/(:any)'] = "products/search/$1/$2";
    

     

    It works fine when the URL is something like "products/search/all/03241/" but not when it's just "products/search". 

     

    Does anyone know what I'm doing wrong?

  4. I have a controller and I have quite a few functions that use the same block of code

     

    //Load the cart library
    $this->load->library('cart');
            
    //Get the contents, total amount and total items of the cart
    $aData['cart'] = $this->cart->contents();
    $aData['cart_total'] = $this->cart->total();
    $aData['total_items'] = $this->cart->total_items();
    

     

    As I use this block several times I decided to put it in a function. 

     

    function getCart() {
        //Load the cart library
        $this->load->library('cart');
            
        //Get the contents, total amount and total items of the cart
        $aData['cart'] = $this->cart->contents();
        $aData['cart_total'] = $this->cart->total();
        $aData['total_items'] = $this->cart->total_items();
    
        return $aData;
    }
    

     

    However when I try to call this function from a another one it never works and the variables are empty. 

     

    If I do

     

    $this->getCart();
    

     

    or this

     

    $aData = $this->getCart();
    

     

    It never works.  Does anyone know what I'm doing wrong?

  5. I have the following query

     

    SELECT product_data.product_id, product_data.product_name, product_pricing.sales_price_inc_vat, products_to_categories.*  FROM product_data, product_pricing, products_to_categories WHERE product_data.product_id = product_pricing.product_id AND product_data.product_id = products_to_categories.product_id LIMIT 10

     

    This works fine but the query takes a long time to excecute because it compares the "product_data.product_id" twice to two tables.  Is there a way to do this comparison but to speed up the execution time?

     

    Thanks for any help

  6. I have the following sql which should return quite a few rows of data but I run it it returns an empty set.  Then when I ran the explain function it said there was an impossible where clause. 

     

    SELECT product_data . * , product_pricing . * , products_to_categories . *

    FROM product_data, product_pricing, products_to_categories

    WHERE product_pricing.product_id = product_data.product_id

    AND product_pricing.sales_price_inc_vat

    BETWEEN 1.00

    AND 2000.00

    ORDER BY product_pricing.sales_price_inc_vat DESC

    LIMIT 20

     

    So the sql should get all the products where the price is within a certain range.  Does anyone know what I'm doing wrong?

     

    Let me know if you need the table structures but they are pretty big

     

    Thanks for any help!

  7. I have a controller that loads the cart library and then has a function to add an item to the cart. 

     

    function add($id, $qty, $price, $name)
    {
         $data = array(
               'id'      => $id,
               'qty'     => $qty,
               'price'   => $price,
               'name'    => $name,
               'options' => array('Option1' => '1')
            );
    
        $this->cart->insert($data);
    }
    

     

    This function works fine if the name of the item is one word.  However when I exceed one word for the name it won't add the item to the cart. 

     

    I am running this function through an AJAX request and I have tried encoding the URL but that doesn't seem to work. 

     

    Thanks for any help. 

  8. I have a function called "search" that handles a form submission.  When I submit the form the URL is "products/search/".  Is there a way to make the controller function output a different URL so instead it would be "products/search/searchCat/searchString" where searchCat and searchString are the two post values from the form? 

     

    Below is my function

     

        function search()
        {
            $searchCat = $this->input->post('searchCat');
            $searchString = $this->input->post('searchString');
            $aData['query'] = $this->ProductModel->GetProductsBySearch($searchCat, $searchString);
           
            $aData['base_url'] = base_url();
            $aData['breadcrumbs'] = create_breadcrumb();
            
            $this->load->view('product_layout', $aData);
        }
    

     

    Thanks

  9. I have a form in one of my view files and I have a function that handle the form data but how do I get that function to run when the form is submitted? 

     

    I tried to use the header function as shown below but that returned an error because the headers had already been sent

     

    header("Location: index.php/products/search/" . $_POST['searchCat'] . "/" . $_POST['searchString'] . "/");
    

     

    Does anyone know the best way to access a controller function from a view? 

     

    Thanks

  10. I checked and it is stored in the same field.  Also if I try to use the same code on a post variable so that I remove the "£" before it gets entered into the database it still doesn't seem to remove it.  So if I did the following it doesn't work. 

     

    $products->product_price = str_replace("£", "", $_POST['product-price']);

  11. When getting data from a database I'm trying to use the str_replace function to get rid of any pound signs but it doesn't seem to be working.  My code is below. 

     

    str_replace("£", "", $array['product_price'])
    

     

    I've also tried replace "£" with "£" but that doesn't work either.  Does anyone know why that's happening?

     

    Thanks for any help. 

     

     

  12. On a web page I'm developing I have a file input field that allows the user to upload an image.  However is it possible to instead of the input field, have an icon that when clicked launches the window for the user to attach a file.  Then once the users has attached an image it stores the path to that image in a hidden input somewhere?

     

    Thanks for any help.

  13. I have a table called "orders" and I want to perform multiple counts on the table.  The first count I want to perform is to get the total number of records.  The second count will be to get the total records where type="everyday" and status="pending".  The third count will count the total or records where type="everyday" and status="sent". 

     

    I have the following sql which works but at the moment the figures it returns seem to be wrong.  All of the counts return 1800 when there are only 34 records in the table.  Can anyone see anything wrong with my sql?

     

    SELECT COUNT(o.status), COUNT(o2.status), COUNT(o3.status) FROM orders AS o LEFT JOIN orders AS o2 ON (o2.type="Everyday" AND o2.status="Pending") LEFT JOIN orders AS o3 ON (o3.type="Everyday" AND o3.status="Sent") WHERE o.company_name="RHB Exports"

     

    Thanks for any help

  14. I have a sql statement which is

     

    select * from invoices where username="gtd" order by invoice_date

     

    I want to edit it so to get the total of a field called "invoice_total" so the statement will now look like this

     

    select *, sum(invoice_total) from invoices where username="gtd" order by invoice_date

     

    However when I do this I now only get 1 record returned rather than before when I got 5 records returned.  Is there are way to get around this problem?

     

    Thanks for any help

  15. I have lots of different forms on lots of different pages.  I mean when the user refreshes the page or presses back this message appears in the browser "To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier."

     

    I was just wondering if there is an easy way to clear POST variables. 

  16. I'm currently working on a website that contains a lot of forms and I keep having the problem where the POST data is resent every time the page is refreshed.  As well as being annoying it's not good for the user.  Does anyone have any tips or techniques about how to solve this problem?

     

    Thanks for any help. 

  17. I have just begun to play around with inheritance when using OOP and have come across a problem. 

     

    I have two classes, one called "firstClass" that is the parent class and another that is called "secondClass" that is the child class.  I know that in the child class I can override the methods in the parent class but do you have to override them completely or can you just override certain bits of them? 

     

    For example say in I have this method in the firstClass. 

    function doSomething() {
        $firstline = "<p>Hello</p>";
        $secondlne = "<p>World</p>";
        $thirdline = "<p>!</p>"
    }
    

     

    Then what do I do if I only want to override the second line of this function in the child class "secondClass"?  Is it best to just override everything or are there recommended design patterns for this sort of thing?

     

     

    Thanks for any help. 

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.