{"id":3020,"date":"2014-03-13T12:11:55","date_gmt":"2014-03-13T12:11:55","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/13\/phplaravellaravel-routingrelated-issues-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:45:33","modified_gmt":"2022-08-30T15:45:33","slug":"phplaravellaravel-routingrelated-issues-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/13\/phplaravellaravel-routingrelated-issues-collection-of-common-programming-errors\/","title":{"rendered":"php,laravel,laravel-routingRelated issues-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/cef6e5e6c34c61b6da403216f033d3a9?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJosh<br \/>\nphp mysql<br \/>\nI have a file \/admin\/php.php which has the following:&lt;?php$ID=$_GET[&#8216;ID&#8217;];require(&#8220;..\/admin\/config.php&#8221;);$sql = &#8220;SELECT * FROM contacts WHERE contacttype IN (&#8216;New&#8217;,&#8217;Buyer&#8217;,&#8217;Seller&#8217;,&#8217;Buyer \/ Seller&#8217;,&#8217;Investor&#8217;) AND leadstatus = &#8216;New&#8217; ORDER BY date DESC&#8221;;$space = (!empty($row[&#8216;firstname&#8217;]) &amp;&amp; !empty($row[&#8216;lastname&#8217;])) ? &#8216; &#8216; : &#8221;; $name = $row[&#8216;firstname&#8217;].$space.$row[&#8216;lastname&#8217;]; $partner = $row[&#8216;spousefirst&#8217;]; $cell = (!empty($row[&#8216;phonecell&#8217;])) ? &#8221; {$row[&#8216;phonecell&#8217;<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/e8qwD.gif?s=32&amp;g=1\" \/><br \/>\nOrangepill<br \/>\nphp<br \/>\nI was troubleshooting some code and I took it out of the execution path so that I could look in other places.PHP continued to call out the code as an error despite it not being executed. It is in a function that is not called.Is this expected behavior?\/\/ not in execution path$temp1 = $this-&gt;hash;$temp = array(&#8216;1&#8217;, $temp1); \/\/ this is line 121$this-&gt;database_object-&gt;_pdoQuery(&#8216;none&#8217;, &#8216;update_picture&#8217;, $temp );syntax error, unexpected T_LNUMBER, expecting &#8216;]&#8217; in\/home\/foo\/public_html\/dev\/<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/fbbfed06147a1aa66fa359c49776299a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nStefan Vogt<br \/>\nphp url urldecode<br \/>\nI have: http:\/\/www.example.com\/index.php?amount=15%252E8In index.php:$test = $_GET[&#8216;amount&#8217;];echo $test; \/\/ Output: 15%2E8But I don&#8217;t need 15%2E8, I need 15.8$test = $_GET[&#8216;amount&#8217;];$test = urldecode($test);echo $test; \/\/Output: 15.8But in http:\/\/us2.php.net\/manual\/en\/function.urldecode.php they warn: Warning: The superglobals $_GET and $_REQUEST are already decoded.Using urldecode() on an element in $_GET or $_REQUEST could haveunexpected and dangerous results.Why $_GET[&#8216;amount&#8217;] does not get<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/22f882b7efb14f8c657acff69d79e281?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nFlorian<br \/>\nphp function namespaces use<br \/>\nI&#8217;m trying to make the following work:function flosoftdedicated_api_init() { require_once &#8216;resources\/vendor\/autoload.php&#8217;; use \\Ovh\\Common\\Ovh;&#8230;.$ovh = new Ovh($config); return $ovh; }function flosoftdedicated_ClientArea($params) { global $ovh;$ovh = flosoftdedicated_api_init(); &#8230;. }but I get the error: Parse error: syntax error, unexpected T_USE in &#8230;.\/flosoftdedicated.php on line 35 Line 35 being the use statement.Is it not possible to use a namespace in a function? Do I need to assign t<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/85d9cc8609ffd73e99a31a1120ccfdaa?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSebas<br \/>\nphp javascript jquery ajax boolean<br \/>\nThis question already has an answer here:How to convert string to boolean php6 answerslet&#8217;s say we have the following ajax:$.ajax({url:&#8217;myURL.php&#8217;,data:{ac:&#8217;do&#8217;,isDoable:false} });Now at the back end when reading the call data, the isDoable is a string, and trying to cast it as Boolean: $isDoable = (bool) $_REQUEST[&#8216;isDoable&#8217;];results in $isDoable always being true, even when sent as false. When I encountered this issue I gave up and simply treated it as a string if($_REQUEST[&#8216;isDoable&#8217;] == &#8216;tru<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/a2GIb.jpg?s=32&amp;g=1\" \/><br \/>\nAndrew Lott<br \/>\nphp arrays sorting<br \/>\nI want to apply different sorting on my array but I am getting unexpected results. This is my array result:Array ( [0] =&gt; Sony,HTC [1] =&gt; HTC [2] =&gt; AT&amp;T [3] =&gt; Sony [4] =&gt; BlackBerry [5] =&gt; Nokia [6] =&gt; Toshiba [7] =&gt; Altori )When I print this array using sort($rows,SORT_ASC) it displays &#8216;1&#8217;.$rows as the array that contains elements. Can anybody find what the problem here is?I want to sort the array with different options like (SORT_REGULAR,SORT_NUMERIC).<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/51956d69017d88b201fbe3cadc7eb779?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nrichard<br \/>\nphp arrays parsing loops syntax<br \/>\nI am trying to loop array from database in email.php but i am getting this error:Parse error: syntax error, unexpected &#8216;;&#8217;, expecting &#8216;)&#8217; in \/home\/xxx\/public_html \/email.php on line 62 This is the code in email.php:$allowed_senders = Array($query = &#8220;SELECT email FROM members&#8221;; \/\/ Line 62$result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $loop_email = $row[&#8217;email&#8217;];echo &#8220;&#8216;&#8221;.$loop_email.&#8221;&#8216;,&#8221;; } ); I don&#8217;t understand what went wrong. Any help?<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/819a82c94b061b6a30dd2a24203b3a78?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nYeshwanth Venkatesh<br \/>\nphp ajax codeigniter form-validation<br \/>\nI am trying to validate a form and save it in my database. I am using codeigniter&#8217;s validation library and it fails. this is the ajax function inside the view function save_form(){ $.ajax({url: &#8216;\/projects\/cafe\/index.php\/welcome\/save_form&#8217;,type: &#8216;post&#8217;,data: {&#8216;fname&#8217; : $(&#8216;#fname&#8217;).val(),&#8217;lname&#8217; : $(&#8216;#lname&#8217;).val(),&#8217;story_name&#8217; : $(&#8216;#story_name&#8217;).val(),&#8217;email&#8217; : $(&#8216;#email&#8217;).val(),&#8217;address_street&#8217; : $(&#8216;#address_street&#8217;).val(),&#8217;city&#8217; : $(&#8216;#city&#8217;).val(),&#8217;state&#8217; : $(&#8216;#state&#8217;).val(),&#8217;zip&#8217; : $(&#8216;#zip&#8217;)<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/6e3ae23a8f4754edf928dfbece0ecabe?s=32&amp;d=identicon&amp;r=PG&amp;f=1\" \/><br \/>\nConcurrentHashMap<br \/>\nphp constants<br \/>\nI have a lot of pages, all of which require the file characters.php. This file contains constants which define many things in my website. They are defined like this, for example:const $humanHEALTH = 1.1;Everything works properly running it in my localhost using WAMP, but when I upload it to an online host I get this error:Parse error: syntax error, unexpected T_CONSTI used phpinfo() on one of the pages and the PHP version is 5.2.17.Any help would be greatly appreciated.<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/9da1fe0ca09c408213402533ff38812c?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nhalfer<br \/>\nphp cakephp<br \/>\nI have this line of code, unfortunately though it has a syntax error:Parse error: syntax error, unexpected T_DOUBLE_ARROW on line 1Here is the code:&lt;?php echo $this-&gt;Html-&gt;link(&#8216;View\/Edit&#8217;, array(&#8216;action&#8217; =&gt; &#8216;view&#8217;, $client[&#8216;Client&#8217;][&#8216;id&#8217;]), &#8220;?&#8221; =&gt; array(&#8216;nc&#8217; =&gt; time(), array(&#8216;class&#8217; =&gt; &#8216;view&#8217;)); ?&gt;Where is the mistake in here and how can I get this resolved?<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/0a98b66b06837c96c99ddfa943b2f52e?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nShnd<br \/>\nlaravel laravel-4<br \/>\nI got Laravel 4 zip file from gitHub. (&#8220;laravel-master&#8221;). run composer and get all the dependencies. i can access it from: &#8220;127.0.0.1\/laravel-master\/public&#8221;but when i rename the &#8220;laravel-master&#8221; to other names, and then try to access it, i get:&#8221;HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.&#8221; I can not figure out what&#8217;s going wrong !<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/ab8EZ.jpg?s=32&amp;g=1\" \/><br \/>\nRoopendra<br \/>\nphp laravel<br \/>\nI&#8217;m trying to use two params with a named route through a controller, but receive an error when loading the viewRouteRoute::get(&#8216;agendarVehiculo\/{idvehiculo}\/{idcita}&#8217;, array(&#8216;as&#8217; =&gt; &#8216;agendarVehiculo&#8217;, &#8216;uses&#8217; =&gt; &#8216;AgendamientosController@addAgendaCitaVehiculo&#8217;));View&lt;td&gt; &lt;a href=&#8221;{{ route(&#8216;agendarCitaPaciente&#8217;, [$paciente-&gt;id, $cita-&gt;id ] }}&#8221; class=&#8221;btn btn-xs btn-success&#8221;&gt; &lt;i class=&#8221;fa fa-calendar&#8221;&gt; Agendar&lt;\/i&gt;&lt;\/a&gt; &lt;\/td&gt;Errorsyntax error, unexpecte<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/ce2a78842d9de0c9ab48e4ed3c473b3e?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAntonio Carlos Ribeiro<br \/>\nlaravel laravel-4<br \/>\nWhen I run composer.phar installI get this error almost at the end of the installation, any ideas?Loading composer repositories with package information Installing dependencies (including require-dev) from lock file Nothing to install or update Generating autoload filesWarning: Unexpected character in input: &#8216;\\&#8217; (ASCII=92) state=1 in \/home\/belendez\/public_html\/laravel\/artisan on line 46Parse error: syntax error, unexpected T_STRING in \/home\/belendez\/public_html\/laravel\/artisan on line 46 Script<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/d0942191fb6abb8c3857049126aa6c03?s=32&amp;d=identicon&amp;r=PG&amp;f=1\" \/><br \/>\nSLim<br \/>\nphp laravel laravel-4 laravel-artisan<br \/>\nWould like to know how can i execute the PHP Artisan script inside my controller of Laravel? Tried the following code but it doesn&#8217;t work.php \/Users\/sl\/Dropbox\/Development\/ABC\/artisan currency:update;This is the error returned: syntax error, unexpected &#8216;currency&#8217; (T_STRING)Thanks<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/c1201849caa3693e9b41824351c9dc3d?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nRubens Mariuzzo<br \/>\nlaravel twig sentry cartalyst-sentry<br \/>\nI&#8217;m trying to check if Sentry user is logged in on twig template on a Laravel project, i&#8217;m using twigbridge.How do i?{% if Sentry::Check() == false %}This gives me:Unexpected token &#8220;punctuation&#8221; of value &#8220;:&#8221; (&#8220;end of statement block&#8221; expected) in &#8220;layouts.menu&#8221; at line 61Same for:{{ Sentry::getUser()-&gt;first_name }}<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/graph.facebook.com\/100006095705135\/picture?type=large\" \/><br \/>\nBhadresh Arya<br \/>\nhtml laravel<br \/>\nWhile using HTML Placeholder with class in Laravel 4, shows me this error.Symfony \\ Component \\ Debug \\ Exception \\ FatalErrorException syntax error, unexpected &#8216;;&#8217;I&#8217;ve used{{ Form::text(&#8216;name&#8217;, null, array(&#8216;class&#8217; =&gt; &#8216;form-control&#8217;, &#8216;placeholder&#8217; =&gt; &#8216;Your Name&#8217;) }}<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/172ac896352143f531fb27b7ad6ea358?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMark Lewis<br \/>\nphp laravel<br \/>\nI was referred to Juggling Larger Laravel Applications and I&#8217;m havihng trouble gettingView::addNamespace(&#8216;Marketing&#8217;, __DIR__.&#8217;\/..\/Views&#8217;)to work in one of my sub-app directories where the views are located at \/var\/www\/myapp.com\/app\/MyApp\/Marketing\/Views Placing this code in my \/var\/www\/myapp.com\/app\/MyApp\/Marketing\/Providers\/MarketingServiceProvider.php&lt;?php namespace MyApp\\Marketing\\Providers;use Illuminate\\Support\\ServiceProvider; use Illuminate\\Support\\Facades\\View;class MarketingServiceP<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/ufYGl.jpg?s=32&amp;g=1\" \/><br \/>\nAlex Morrise<br \/>\nphp laravel<br \/>\nI am trying to copy a project from localhost to live server done in Laravel 4 framework. On the local machine it is working, but I have this error in live server:Warning: Unexpected character in input: &#8216;\\&#8217; (ASCII=92) state=1 in \/**********\/laravel\/bootstrap\/autoload.php on line 46Parse error: syntax error, unexpected T_STRING in \/**********\/laravel\/bootstrap\/autoload.php on line 46I didn&#8217;t modify those files.Thanks<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/827d9f7b90c6434a86c9c73ee4080eb8?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAnand mohan sinha<br \/>\nphp laravel<br \/>\nI am using laravel for my php project everything worked fine in devlopment but during hosting since i wasen&#8217;t given a shell access on server so i could not create a symlink . so i moved the contents of public folder to root and changed index.php accordingly . but i have been getting this errorWarning: chdir() [function.chdir]: No such file or directory (errno 2) in \/home\/saarorgi\/public_html\/paths.php on line 62Parse error: syntax error, unexpected T_STRING in \/home\/saarorgi\/public_html\/larav<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/8aff1b9e8079997cca12f8f08cacbb62?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nedi9999<br \/>\nphp testing laravel phpunit laravel-4<br \/>\nI&#8217;m trying to create some tests.Here&#8217;s my Test Class:class ExampleTest extends TestCase {public function setUp(){parent::setUp();Artisan::call(&#8216;migrate&#8217;);$this-&gt;seed();Auth::loginUsingId(1);}public function testActionUpdateNew(){$action = new Action(Array());$action-&gt;save();var_dump($action-&gt;id);Action::with(&#8216;reponses&#8217;,&#8217;contact&#8217;,&#8217;user&#8217;,&#8217;etudiant&#8217;,&#8217;entreprise&#8217;,&#8217;etude&#8217;)-&gt;findOrFail($action-&gt;id);}public function testEtudes(){$etudes=Etude::all()-&gt;toArray();$this-&gt;assertCount(10<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/lRkrq.jpg?s=32&amp;g=1\" \/><br \/>\ncore_m<br \/>\nmodel controller laravel laravel-4 laravel-routing<br \/>\nI can&#8217;t get rid of the errors. I&#8217;ve created an model, and have functions in controllers and a route, but I get errors.my model(newsticker.php):&lt;?phpclass Newsticker extends Eloquent {protected $table = &#8216;aac_newsticker&#8217;;protected $fillable = array(&#8216;label&#8217;, &#8216;content&#8217;);public $timestamps = true; }my controller (also used for other functions, but used also for newstickers):&lt;?phpclass NewsController extends BaseController {\/*** News Repository** @var News*\/protected $news;public function __cons<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/40de750233b3ce8268f235ba0b6a489b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nteresko<br \/>\nphp laravel laravel-routing<br \/>\nI&#8217;m trying to access the name of the current controller and the current method to pass it to my view as a variable. I&#8217;ve tried several ways from pointers I found online but they don&#8217;t work so I assume they were for Laravel 3.Here is what I&#8217;ve triedRequest::$route-&gt;controllergivesAccess to undeclared static property: Illuminate\\Support\\Facades\\Request::$routeandRequest::route()-&gt;controllergivesCall to undefined method Illuminate\\Http\\Request::route()<\/li>\n<\/ul>\n<p>Web site is in building<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Josh php mysql I have a file \/admin\/php.php which has the following:&lt;?php$ID=$_GET[&#8216;ID&#8217;];require(&#8220;..\/admin\/config.php&#8221;);$sql = &#8220;SELECT * FROM contacts WHERE contacttype IN (&#8216;New&#8217;,&#8217;Buyer&#8217;,&#8217;Seller&#8217;,&#8217;Buyer \/ Seller&#8217;,&#8217;Investor&#8217;) AND leadstatus = &#8216;New&#8217; ORDER BY date DESC&#8221;;$space = (!empty($row[&#8216;firstname&#8217;]) &amp;&amp; !empty($row[&#8216;lastname&#8217;])) ? &#8216; &#8216; : &#8221;; $name = $row[&#8216;firstname&#8217;].$space.$row[&#8216;lastname&#8217;]; $partner = $row[&#8216;spousefirst&#8217;]; $cell = (!empty($row[&#8216;phonecell&#8217;])) ? &#8221; {$row[&#8216;phonecell&#8217; Orangepill php I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,1],"tags":[],"class_list":["post-3020","post","type-post","status-publish","format-standard","hentry","category-laravel","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3020","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3020"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3020\/revisions"}],"predecessor-version":[{"id":8841,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3020\/revisions\/8841"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3020"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3020"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}