EllisLab text mark
Advanced Search
     
How to fix this variable assignment?
Posted: 10 November 2012 11:38 PM   [ Ignore ]
Avatar
Joined: 2010-11-24
56 posts

Hi guys

How to fix this codes below,

public $main_page base_url() . 'jaz/'

As you can see the codes above will produce an error below,

Parse errorsyntax errorunexpected '('expecting ',' or ';' in /home/site_removed/public_html/admins9b/application/controllers/jaz.php on line 10 

So how do I assign the value/string above the proper way?

Thanks in advanced.

 

 Signature 

Sorry, Just asking… ^__^

 
Posted: 10 November 2012 11:45 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2010-11-24
56 posts

These are the complete codes,

<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');

class 
Jaz extends MY_Controller
{
 
public $data = array(
                   
'' => '',
    );
    
 public 
$main_page $base_url() . 'jaz/';
  
 
    function 
__construct()
    
{
        parent
::__construct();
        
$this->load->helper('general');
        
$this->load->model('users_model');
  
$this->load->library('email');
     
}

Why it’s producing error?

 Signature 

Sorry, Just asking… ^__^

 
Posted: 11 November 2012 02:58 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2009-04-15
453 posts

your two sets of posted code are different.

the “real” one:

public $main_page $base_url() . 'jaz/'

is using the function base_url() as a variable (i.e., __$__base_url() )


after that, you should declare:

public $main_page;

then in the __construct() function set it as:

$this->main_page = base_url() . ‘jaz/’;


Before you call the construct of the controller, you don’t have a reference to the $CI object, and so the url helper, etc are not loaded yet

 Signature 

Code By Jeff

Mahana Messaging Library

Problem with your query? Did you run

$this->db->last_query(); 

before you came to the forums for help?

 
Posted: 11 November 2012 11:32 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2011-02-23
882 posts

Nope, that’s not the problem. PHP allows just a variable type declarations when defining attributes. You cannot assign variables directly.

This does not work

class Test {
  
public $thingy base_url();
  public 
$thongy = array('base' => 'here);

Howerver, such things work

class Test {
  
public $null NULL;
  public 
$array = array();
  public 
$false FALSE;
  public 
$true TRUE;
  public 
$string "";
  public 
$empty '';

Any other value assignment (as you do with public $item = base_url() must be done in the class constructor.

That’s how PHP rolls!

 Signature 

ignited Community Framework (WiP)  |  Read the User’s Guide. It won’t bite.

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

CI example .htaccess