Codeigniter link according to function? - codeigniter

In my codeigniter code there is a php controller Product.
<?php
class Product extends CI_Controller
{
function index($product_id)
{
......
....
}
}
what is the link of this function. I try localhost/demo/product/index/2 here 2 is product_id,demo is project_name . But this link does not work?

Related

How can i get result from model in laravel 5

Good day, i'm trying to get the result from my model that called with Mainmodel through my controller, my controller is MainController.
Here is my controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use app\Mainmodel;
class MainController extends Controller
{
function index(){
echo "Kok, direct akses sih?";
}
function get_menu(){
$menu = app\Mainmodel::request_menu();
dd($menu);
}
}
Here is my model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Mainmodel extends Model
{
function request_menu(){
$menu = DB::table('menu')
->orderBy('[order]', 'desc')
->get();
return $menu;
}
}
my routes
Route::get('menu','MainController#get_menu');
with my script above i get this
FatalErrorException in MainController.php line 17: Class
'App\Http\Controllers\app\Mainmodel' not found
how can i fix this ? thanks in advance.
Note: I'm bit confuse with laravel. I'm using codeigniter before. And i have a simple question. In laravel for request to database should i use model ? or can i just use my controller for my request to database.
sorry for my bad english.
I would imagine it's because your using app rather than App for the namespace.
Try changing:
app\Mainmodel
To:
App\Mainmodel
Alternatively, you can add a use statement to the top of the class and then just reference the class i.e.:
use App\Mainmodel;
Then you can just do something like:
Mainmodel::request_menu();
The way you're currently using you models is not the way Eloquent should be used. As I mentioned in my comment you should create a model for each table in your database (or at least for the majority of use cases).
To do this run:
php artisan make:model Menu
Then in the newly created Menu model add:
protected $table = 'menu';
This is because Laravel's default naming convention is singular for the class name and plural for the table name. Since your table name is menu and not menus you just need to tell Laravel to use a different table name.
Then your controller would look something like:
<?php
namespace App\Http\Controllers;
use App\Menu;
class MainController extends Controller
{
public function index()
{
echo "Kok, direct akses sih?";
}
public function get_menu()
{
$menu = Menu::orderBy('order', 'desc')->get();
dd($menu);
}
}
Hope this helps!
You can solve it by different solution. The solution is you don't have to call request_menu(); you can get it in your controller.
MainController
use use Illuminate\Support\Facades\DB;
public function get_menu(){
$menu = DB::table('menu')
->orderBy('Your_Field_Name', 'DESC')
->get();
dd($menu);
}

Two Application in Codeigniter

How to code 2 application on codeigniter.
Example I have 2 application : Facebook and twitter use Codeigniter.
On home I can choose go to facebook or twitter.
This is a easy demo.
In controllers folder:
You create a controller: Home_controller
class Home_controller extends CI_Controller {
public function index()
{
echo "<a href ='index.php/facebook_controller'>Facebook</a><br>";
echo "<a href ='index.php/twitter_controller'>Twitter</a>";
}
}
Then you create facebook_controller and twitter_controller like this:
Facebook_controller:
class Facebook_controller extends CI_Controller {
public function index()
{
echo "This is facebook_controller";
}
}
Twitter_controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Twitter_controller extends CI_Controller {
public function index()
{
echo "This is twitter_controller";
}
}
Hope this help.

CodeIgniter + PHPExcel: What is best way to call this library to CodeIgniter?

I have PHPExcel, and I want to add it to CodeIgniter.
Where is the best to copy the files from all CodeIgniter folders, and how do I call it in my controllers/models for regular usage?
EDIT:
It's a whole folder that I need to move, and call the main file: PHPExcel\IOFactory.php
You may add PHPExcel to library in Codeigniter, E.g:
application > libraries > PHPExcel.php
Let say in PHPExcel.php library file:
<?php
if (!defined('BASEPATH')):
exit('No direct script access allowed');
endif;
class PHPExcel
{
public function __construct()
{
//
}
public function some_function()
{
return 'some_function';
}
}
To call PHPExcel library, in your Controller. Let say I named it as
My_controller.php:
<?php
if (!defined('BASEPATH')):
exit('No direct script access allowed');
endif;
class My_controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
//Call PHPExcel class
$this->load->library('PHPExcel');
}
public function index()
{
echo $this->PHPExcel->some_function();
}
}
I followed this tutorial: https://arjunphp.com/how-to-use-phpexcel-with-codeigniter/
Got my answer !

Autocrumb in Codeigniter?

I woul like to create autocrumb in CI
I use this library : http://codeigniter.com/forums/viewthread/137949/
but my problem is like that in my controller. I have 2 functions for example :
Class MyControlleur CI_controller {
public function Shoes () {}
public function Men () {}
}
I would like to have somethin like that :
Home > Shoes > Men
thanks !!
The best breadcrumb I have ever come through for CI is https://github.com/broncha/codeigniter-breadcrumb
Autoload the breadcrumb library
In your controller construct you add a breadcrumb to your controller
class Content extends CI_Controller{
public function __construct(){
$this->breadcrumb->append_crumb('Content', site_url('content'));
}
public function add(){
$this->breadcrumb->append_crumb('Add Content', '#');
}
}
In your view $this->breadcrumb->output();

Load Model in HMVC

I am trying to load a model within the same module from a controller.
$this->load->model('pendingAccountModel');
but the model could not be loaded.
the module dir is accounts.
the model file path is: app/modules/accounts/models/pendingAccountModel.php
the model decleration is:
class PendingAccountModel extends Model {
function __construct(){
parent::__construct();
}
}
this is the controller who loads the model:
class PendingAccount extends MX_Controller {
function __construct(){
parent::__construct();
}
function register($data_arr)
{
$this->load->model('pendingAccountModel');
}
}
CI 1.72 with latest hmvc
Thanks
had a quick read through the HMVC docs ~
$this->load->model('pendingAccountModel');
the docs suggest that you should include the module name in the include path
so try (perhaps) $this->load->model('accounts/pendingAccountModel');
also note your "PendingAccount" controller needs to be in:
app/modules/accounts/controllers/PendingAccount.php

Resources