How to call helper in view - codeigniter

I made a helper and save it as MY_skm_helper.php,
and call it in my view like this
$this->load->helper('MY_skm');
but it shows error like this:
Unable to load the requested file: helpers/my_skm_helper.php

First rename your helper with my_skm_helper.php
load your helper in controller better in __construct
$this->load->helper('my_skm');

Are you trying to override a helper? if that's a custom helper, try removing the 'MY_' prefix then load it using its name without '_helper'
ex:
rename the my_skm_helper to skm_helper. then, load it like this in one of your controllers.
$this->load->helper('skm');

Related

how to use two functions from same controller in single page route using get in laravel

Am trying to use two different functions from one controller in a single page route
Route::get('/cart','App\Http\Controllers\Frontend\CartController#index');
Route::get('/cart','App\Http\Controllers\Frontend\CartController#alldata');
But the problem is the function alldata works where the function index doesn't
You can't have 2 GET routes with the same path.
Route::get('/cart','App\Http\Controllers\Frontend\CartController#index');
Route::get('/cart/all','App\Http\Controllers\Frontend\CartController#alldata');
The /cart route is overwritten by the alldata(). So the alldata() is calling instead of index().
kindly remove the alldata()'s route and pass the data from index().
Route::get('/cart','App\Http\Controllers\Frontend\CartController#index');
Route::get('/cart','App\Http\Controllers\Frontend\CartController#alldata');
Try to manipulate your logic in controller rather than in route file.
Use conditional in controller function.

Creating a new page in Laravel

I'm trying to create a new page in Laravel and I'm not sure what to do in the context of the Laravel framework.
If it was just html, then you just create a new html file. In Laravel, what are all the things you need to do when creating a new page?
The easiest way in Laravel is to define a route closure, and return a view from it.
In your routes/web.php file:
Route::get('/my-page', function () {
return view('my-page');
});
Then in resources/views you create a file called my-page.php, or if you want to use Laravel's Blade syntax (you probably do) call it my-page.blade.php.
Edit: there's now an even easier way to to it. Also in routes/web.php:
Route::view('/my-page', 'my-page');
This will do exactly the same thing as the previous example, without the need for a closure and explicitly calling view().
There are two locations to add New Page to your Laravel project:
You have to create an additional route in YOURAPP>routes>web.php file.
You have to add PHP file with that name to YOURAPP>resources>views folder. If you want to use BLADE for your project, than you should put name_of_page.blade.php. And you should concider it as a must at the very beginning :).
Now, in routes you should be able to add only first part of the file rather than .blade.php. For example: about.blade.php, you can put in route only about
It should work out of the box :).
You can also try this in routes/web.php
Route::get('/my-page', function () {
return view('my-page');
})->name('my-page');

Using underscore synatx in URI with implicit controller in laravel

I know this:
If your controller action contains multiple words, you may access the action using "dash" syntax in the URI. For example, the following controller action on our UserController would respond to the users/admin-profile URI:
public function getAdminProfile() {}
Want to the know about:
If i want to use "underscore" synatx in the URI. Is it possible with implicit controllers.
Like want to use user/admin_profile in the URI. What would controller look like?
You can do something like this.
In your routes.php file add
Route::get('user/admin_profile', 'UserController#getAdminProfile');

Getting the controller?

In my view I create links via:
URL::action('NotSureWhatController#getIndex', 'id') }}
My view is a template that is used by a variety of different controllers, what's the best way to change the name of the controller in the action?
The only thing I can think of is setting a var in the controller and passing it through.
Is there a better way? Or a way to get the controller name?
I can't use 'as' in the route to name the controller either (as this is used for something else) so this won't work:
Route::currentRouteName()
Option 1
You should create the URL directly in the controller, then pass it as a variable to the view. The view will just print the url.
Option 2
You pass the name of the controller as a variable to the view (always from the controller), then you use the escape values of the blade templating to print it inside your function to generate URLs.
Option 3
Using the REQUEST class to get information about the page.

How to fetch data from controller to views in CakePHP or Yii

How to fetch data from controller to views in CakePHP or Yii but not embed PHP code in views file (view is html file).
it similar Template Parser Class in Codeigniter:
https://www.codeigniter.com/user_guide/libraries/parser.html
You will need to load the data in the action controller by calling one of the model functions like findAll()
here is an example, assume we have a User model, and you need to pull out all the data and render them at view file:
public function actionIndex(){
$model = Users::model()->findAll();
$this->render('index', array('model' => model));
//the model variable will be defined in the index.php
//file and will have a value as assigned in the array
//index.php file should be located under /views/users/index.php
}
Now in index.php file do a var_dump and see what results you got.
I don't see the problem with embedding php into HTML. But if you really don't want to do it, you can use CakePHP with a template library like Mustache.
Check this: https://github.com/electblake/CakePHP-Mustache-Plugin

Resources