Parse Error Syntax Error Unexpected T_variable In Codeigniter
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of syntax error, unexpected '$this' (t_variable) this site About Us Learn more about Stack Overflow the company Business Learn
Syntax Error, Unexpected '$this' (t_variable) In Codeigniter
more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question
Codeigniter Parse Error Syntax Error Unexpected
x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Why
T_constant_encapsed_string
am I getting an unexpected T_VARIABLE error in my Code Igniter controller? up vote 0 down vote favorite I have this controller in Code Igniter that begins with class MyController extends CI_Controller { private $data = array( 'importantValueToPassToViews' => $this->Animal->getPrey(), ); ... I am getting an error on the line beginning with 'importantValueToPassToViews' (the third line). Parse error: syntax error, unexpected T_VARIABLE Why? php codeigniter share|improve this question asked Apr 7 '12 at 19:58 John Hoffman 3,801103151 Are you sure Animal is a field and not a class? –Gabber Apr 7 '12 at 20:00 Animal is an autoloaded model. –John Hoffman Apr 7 '12 at 20:01 But it's not autoloaded until the controller is constructed. You're getting an error for at least two different reasons here :P –landons Apr 7 '12 at 20:08 add a comment| 1 Answer 1 active oldest votes up vote 4 down vote accepted Because you can't call a function in a class property definition. You can set it to a constant, or an array of constants. You'll need to do that in the constructor: data['importantValueToPassToViews'] = $this->Animal->getPrey(); } // ... } share|improve this answer answered Apr 7 '12 at 20:00 landons 7,92312040 Thank you. That resolves the original PHP error. However, when I pass $data into a view with $this->load->view('viewPrey', $data);, I cannot access the variable called $importantValueToPassToViews in the view. It apparently doe
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the http://stackoverflow.com/questions/10057867/why-am-i-getting-an-unexpected-t-variable-error-in-my-code-igniter-controller Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Codeigniter - Parse error: syntax error, unexpected '$this' up vote -5 down vote favorite I am starting to learn codeigniter. I get this http://stackoverflow.com/questions/28580789/codeigniter-parse-error-syntax-error-unexpected-this error while trying to run the project. Parse error: syntax error, unexpected '$this' (T_VARIABLE), expecting ';' or '{' in C:\xampp\htdocs\Codeigniter\application\models\post.php on line 5 My Model-post.php: class Post extends CI_Model{ function get_posts($num=20, $start=0) $this->db->select()->from('posts')->where('active',1)->order_by('date_added','desc')->limit($start,$num); $query=$this->db->get(); return $query->result_array(); } } My Controller-posts.php: load->model('post'); $data['posts'] = $this->post->get_posts(); print_r($data['posts']); } } php codeigniter share|improve this question edited Feb 18 '15 at 18:00 tereško 42.6k1567124 asked Feb 18 '15 at 10:05 Pradeep 167 Compare this function header: function get_posts($num=20, $start=0) with this one: function index(){ –Rizier123 Feb 18 '15 at 10:10 1 I think the error is on this line: function get_posts($num=20, $start=0). You declare a function without opening the brace. Add the opening brace like this function get_posts($num=20, $start=0) { It's surprising you didn't open the brace, yet you are closing it on the second-to-last line. –Michael Woyo Feb 18
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more http://stackoverflow.com/questions/16752045/codeigniter-parse-error-syntax-error-unexpected-in-user-controler-ph about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Codeigniter - Parse error: syntax error, unexpected '[' in … user_controler.php syntax error [closed] up vote 2 down vote favorite 1 I've been trying to run an existing Codeigniter project that's been finished by a friend. At his computer everything works just fine but when I try to run it on mine this message is shown in the browser: Parse error: syntax error, unexpected "[" in C:\wamp\www\P-project\application\controllers\user_controler.php on line 88 This is the code on line 88: $data = []; This is parse error syntax the code for the function: function Shownews(){ $this->load->model('user'); $data = []; $data['news'] = $this->user->getNews(); $this->load->vars($data); } He's done it so the project URL is : http://localhost/P-project/index.php/user_controler/log We're both using Wampserver for the connection and Netbeans for the project. If anyone can help please do so as soon as you are able, it is urgent. Thank you. php codeigniter share|improve this question edited May 25 '13 at 17:26 Bibhas 7,757114478 asked May 25 '13 at 17:18 John Young 2612 closed as too localized by cryptic ツ, HamZa, Madara Uchiha♦, Jocelyn, andrewsi May 26 '13 at 3:28 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question. I don't know why this question is closed. I had the same problem. It's not Codeigniter specific, but other than that I don't see why this is too localized. –SPRBRN Nov 18 '14 at 15:47 add a comment| 1