Why are view files in CodeIgniter saved with .php extension? - codeigniter

From the CodeIgniter docs, I noticed that the view files are saved with .php extension, even if they only contain html. Is there a logical reason behind this?

It is not compulsory to save view files with the only .php extension we can also save them as HTML files, But to load the HTML views we also need to specify the filename with an extension like $this->load->view('my_view.html').
Also, you can check this link for the same discussion view extension in CodeIgniter 3
Q: When we load any class in CodeIgniter like we load the models, libraries in our controllers without specifying its extensions so how CodeIgniter loads the exact file with that name.
A: For this, There are the system functions defined in the CodeIgniter which concat the .php extension with the class name we pass e.g $this->load->library('form_validation')
For Example: How CodeIgniter 3 actually loads liberaries If you can check the system file in system/core/Common.php line no ~141 function
load_class for liberaries
So it will load system/libraries/Form_validation.php file
I hope this will make you clear that why view files in CodeIgniter saved with .php extension.

Codeigniter is a PhP framework, so it assumes the user is (eventually) going to use PhP.
Also, it isn't necessarily bad practice to always use .php instead of .html since .php handles html just fine. Could be viewed as potential future proofing your code.

One advantage of using the .php extension is that a server can be configured to not display the contents of the file. In other words, the lines of text (php code) that are eventually output to the browser (as html) cannot be seen directly. This provides a layer of security by hiding implementation details from the website user.

Because Codeigniter is a PHP MVC (Model-View-Controller) Framework. The view files are .php because they use PHP scripts. That's the idea, but it's not mandatory. You can include pure HTML. The view files are called by "name-of-the-view-without-the-extension".

Related

Locating the main website (front page) file in cpanel for website built on laravel and voyager

I am trying to locate the file or folder in cpanel that the front page of my website is housed in so i can add a floating action button script to my website.
I just have no prior experience here.
(I am trying to add this in correct place)
It should have a finished result as here http://www.floatingactionbutton.com
The views or 'pages' of the application should be in the resources/views/ directory. You may find a view that is 'home' or something similar but there is no way of knowing what the views have been named when your application was developed.
The views may not be in straight HTML / PHP but rather use Laravel's Blade syntax.
In addition, existing javascript files in your site may have been compiled using Webpack. I imagine the floating action button will be a javascript script.
Can you get the original developer to add the script for you?

need to add css,js files inside the modules folder CI hmvc

I am working on a CodeIgniter - HMVC
What I know:
is I should not create assets like css,js,images inside the application folder in codeigniter, but I have a necessity for it.
**What I am trying to achieve is : **
to create a standalone module and trying to use it in another project. In that case, I really need to add the necessary css,js,images files into the modules folder it self.
The Error I get is:
You don't have permission to access /v7-bitbucket/application/modules/some_modle/assets/bootstrap.min.css on this server.
How do I overcome this?
Please advice.
Thanks.
There are 2 ways I can think of for you to access this data.
The first one is using an htaccess and a custom rule, which redirects certain files to inside the other directory. This way, the user will still have access to only certain specific files outside of the public HTML folder.
The second option is to use PHP and render the content of the file in custom tags.
Ex: Instead of entering <link href="<?= $path ?>">, you would do <style><?= file_get_contents($path) ?></style>. This would be harder to cache, and a bit harder to implement for images.

Change Joomla 3 page url extension from .html to .htm

I am creating a website using Joomla 3 CMS. I have a requirement from my client that i need to change the existing page url extension from .html to .htm. As this website is redesign of a existing website the old links have .htm extension.
Open ../libraries/cms/router/site.php
Go to line number 144
And change
if ($format = $uri->getVar('format', 'html'))
to
if ($format = $uri->getVar('format', 'htm'))
I hope that helps
If you don't want to edit core files, and that is certainly not advised for sake of future upgrades. Your best solution is using a custom component for managing Joomla's SEF URLs, for example: sh404SEF (Paid) or JoomSEF (Free).
Check out http://extensions.joomla.org/category/site-management/sef for others.
Never ever edit Joomla Core files, otherwise when you upgrade Joomla, all your changes will be gone.
As #Alexxandar said; use SEO/SEF components for your needs. I recommend to use MijoSEF (Free or Paid)
Go to global configuration and remove the l from the suffix.
THis is a Joomla configuration question and a standard joomla configuration (not programming) option.
Now the one thing you will have to worry about is that if there are any old links to the htm pages. FOr this you will probably want to use the built in redirect component. Turn on the redirect plugin and then if you have a small number of pages you can just set up the redirection by hand. If you have more pages you may want to write the sql to create a bunch of redirects. Or you might want to make your own plugin to permanently redirect the old to the new.

Laravel 4 - Accessing Folders

I am new to Laravel 4, and I come from a Zend Framework background. I'd like to create a folder app/forms and keep all my forms there. How can I refer to the form in the controller and within the view.blade files?
By default, the root of the view files folder is app/views so if you create a folder in views like app/views/forms then you may refer the form by it's name from a controller like:
$form = View::make('forms.formfile');
Here, formfile is the name of the file that contains the form and it could be formfile.blade.php and to refer/include the form file from a view you may use #include:
// In a blade view file
#include('forms.form1')
Assume that, form1 is a blade view inside the forms folder and saved as form1.blade.php, you may also use sub-folders inside the forms folder, for example in views/forms/user folder you may keep a view named index.blade.php and use it like:
// From a controller
$userForm = View::make('forms/user/index');
From a view file: (folders are separated by .)
#include('forms.user.index') // file: app/views/forms/user/index.blade.php
You can also nest views in the controller, check the manual for more.
From the standpoint of Laravel, HTML forms (and all presentation related things ) belongs to app/views/ folder. Exceptions are package specific views. For example some commands has their own stubs and views and they are usually stored inside package.
Laravel is very flexibile, and you can move things around and create new folders and namespaces. You just have to tell composer that you are changing Laravel default structure, and dumpautoload. That is if you only want to create new folder with internal reference. If you want something with more scope and visibility you'll have to bind that to container, so that will be visible inside whole application.
You are coming from the Zend world, so I can understand that you want to move some of Zend "flavour" to Laravel. Although is it possible, I would really recommend you to take some time and learn how Laravel works. There are some great ideas and design inside. Of course, Zend has its own quality, but hey - this is Laravel :)

How routing is done in codeigniter?

I could not find the .htaccess file in CodeIgniter framework and i'm wondering how do they do route without it? Or it is somewhere hidden?
There is no .htaccess by default provided with codeigniter. They serve it through the index.php. .htaccess is only used to direct the urls to the index.php. This way codeigniter is working in environments where rewriting isn't allowed. Another way of getting controller and function is by query strings.
Anyway the actual routing is done in system/core/Router.php so you can read the code. Since Codeigniter is open source application that can't be hidden.

Resources