Welcome Guest, Not a member yet? Register   Sign In
View string needs escape if back slash on end
#13

(07-04-2019, 08:30 AM)InsiteFX Wrote: For some reason if I use all forward / slashes CodeIgniter throws me the WHOOPS! Error

If I access it like below it works.

PHP Code:
echo view('Insitefx\Admin\Views/'.$slug); 

Namespaces use the back slash \

So my question is this the correct way of defining this url?

Or will this also cause problems?

That is a perfectly accurate way to do it. PHP and Composer (or any other auto-loader that I'm aware of in common use) do not provide the ability to auto-load any files other than classes. What we have provided is a way to "namespace" non-class files, like view files, helpers, etc. This makes code modules work for us and is pretty convenient in many instances, I think.

Technically, the first part of the filename is the namespace, which should use backslashes, i.e. Insitefx\Admin\Views. Anything after that is part of the file path and would typically use forward slashes, though is likely not necessary as MGatner points out. However, I do believe that in order for it to be recognized as having a namespace, you must have at least one backslash in the filename, otherwise it will attempt to interpret those as either folders within app/Views, or part of the filename itself.
Reply


Messages In This Thread
RE: View string needs escape if back slash on end - by kilishan - 07-07-2019, 08:28 PM



Theme © iAndrew 2016 - Forum software by © MyBB