how to use other function in the same controller in magento? - php

im trying to create new module on local. now the module is detect which is name as IndexController.php. this controller consist of two function which is indexAction and testAction .
now the testAction is not detect but the indexAction is detect.
im using this link to run the controller localhost/magentoproject/index.php/test/index which is run as expected
but when i try to run localhost/magentoproject/index.php/test/test is shows that 404 not found.
this is the structure
indexController.php
class Pfay_Test_IndexController extends Mage_Core_Controller_Front_Action {
public function IndexAction() {
$this->loadLayout();
$this->renderLayout();
//echo 'test index';
}
public function testAction() {
echo 'test mymethod';
}
}
this is when im run localhost/magentoproject/index.php/test/index
this is when im run localhost/magentoproject/index.php/test/test

the path will moduelname/controllername/actionmethod in your case the module name will be test controller name will be index and action method will be test
so url will be localhost/magentoproject/index.php/test/index/test

Related

Codeigniter not finding file url helper

So I have this setup:
ARTISTAS
But when I click on that link, it takes me to http://localhost/Universal%20Music/Universal/artistas/index which says 404, like if there's nothing there but I've already created the controller with that name loading some views in it. Am I missing something here?
EDIT
My config.php has:
$config['base_url'] = 'http://localhost/Universal/Universal';
I stop using spaces in the names of the folders and now the path is:
C:\Users\Horacio\Documents\Projects\Universal\Universal
The controller file has the same name of the class I need and the code inside is:
<?php
class Artistas extends CI_Controller {
function __construct() {
parent::__construct();
}
public function index()
{
$this->load->view('header');
$this->load->view('main-index');
}
}

Error:404 page not found, code igniter

controller.php
<?php
define('_root',$_SERVER['DOCUMENT_ROOT']);
include(_root.'/innoshop/application/models/model.php');
// include_once 'model.php';
class Controller {
public $model;
public function __construct()
{
$this->model = new Model();
}
If i put localhost:8888/projectname, i got error like this
404 Page Not Found
The page you requested was not found.
anyone help me
As the guys say you should read the docs as this is very wrong. To fix do this..
class Controller extends CI_Controller{//better to give your controller a more meaningful name
public function __construct(){
parent::__construct();
//use the CI loader - the model will then be available like this $this->model->some_function();
$this->load->model('model');//better to give your model a more meaningful name as well
}
//the index method allows you to use just the controller name in your URI eg localhost:8888/projectname/index.php/controller
public function index(){
echo 'something to see';
}
//an alternative controller method get it like localhost:8888/projectname/index.php/controller/your_method_name
public function your_method_name(){
echo 'something to see in your method';
}
}
If you want rid of the index.php in the URI search for questions related to .htaccess in CodeIgniter
If you want to be able to use a uri like this localhost:8888/projectname then you need to add a route in config/routes.php that defines the default controller like this $route['default']='controller';

how to create frontend controller and action in gocart

I am facing some problems in gocart codeigniter. I create a front end controller named decorate
then action named products and passing slug in action.
Following is the code of controller
<?php
class Decorate extends Front_Controller {
function __construct()
{
parent::__construct();
//make sure we're not always behind ssl
remove_ssl();
$this->load->model(array('Decorate_model'));
$this->lang->load('decorate');
}
function index()
{
$data['page_title'] = lang('decorates');
$data['decorates'] = $this->Decorate_model->get_front_all_decorates();
$this->load->view('decorate_home',$data);
}
/* Single Decorate */
function products($decorate_slug)
{
$data['page_title'] = lang('decorates');
}
}
?>
But when I am running url www.abc.com/gocart/index.php/decorate/products/decorate-1
then it is showing 404 error. I am not getting how to create action in gocart.
Could be Gocart routes everything to one master controller. What's in your routes.php?

Codeigniter: Using url segments in a query

I just started working with CodeIgniter and I am having some trouble with the segment-based urls. I understand how to call them doing $variable = $this->uri->segment(2); but whenever I go to the url, I am getting a 404. Is there something I need to do for URI routing?
For example, I am trying to go to localhost/ci/index.php/games/1000 (where 1000 would be a game ID), but I am getting a 404. localhost/ci/index.php/games/ works fine.
In order for that to work you would need to have a controller called games.php with this content
class Games extends CI_Controller
{
public function index($id)
{
echo $id;
}
}
Unless you do something like this
class Games extends CI_Controller
{
public function index()
{
echo 'this is index';
}
public function game($id)
{
echo $id;
}
}
and add this to your routes.php
$route['game/(:any)'] = "games/game/$1";
By default the 2nd segment of the URI is a method (function) within the controller which CI automatically calls.
So in your case you are actually attempting to call a function named 1000() within the games controller, which doesn't exist and therefore results in a 404.
Instead what I think you want to do is call the index() function, and pass the variable 1000 to it.
So if you were to go to localhost/ci/index.php/games/index/1000 you shouldn't get a 404 anymore, however your URI segment will now be wrong to get the variable 1000.
Here is a working example of the controller with the corrected URI segment:
class Games extends CI_Controller
{
// good habit to call __construct in order to load
// any models, libraries, or helpers used throughout this controller
public function __construct()
{
parent::__construct();
}
// default controller
public function index()
{
// this should display 1000
echo $this->uri->segment(3);
}
}

how to call a function inside a controller in opencart

i have a controller that have with in let's say thingy/stuff directory
<?php public function index() { /*thingy stuff */ }
public function anotherfunction() {/*other thingy stuff*/} ?>
i see tthe url like index.php?route=thingy/stuff&var=dd
what i want is to call an $.post to this function inside that controller
so it uses another template file thingy.tpl and return html to use
what the URL should like ??
i searched for hours ans it sounds like there is no development documentation for open-cart out there
let's say you have a controller called "stuff" under the thingy folder and a function called "my function" within that class, that looks like this:
class ControllerThingyStuff extends Controller {
public function index() {
// Some code
}
public function myfunction() {
// Your code
}
}
if you want to directly communicate with this function using the URL you can add the function name to the end of the route parameter "route=thingy/stuff/myfunction& ..." and load the thingy.tpl inside the function and return it after rendering:
// some code
$this->template = 'template/product/thingy.tpl';
...
$this->response->setOutput($this->render());
if are using the open cart 1.5 and you want to use jQuery AJAX with JSON then you'll need to import the JSON library before rendering:
$this->template = 'thingy/stuff/thingy.tpl';
$json['output'] = $this->render();
$this->load->library('json');
$this->response->setOutput(Json::encode($json));
take a look at the checkout page to get some ideas, the default open cart 1.5 template uses the same technique to load the templates for each section.
It's added to the route if it's not index, which it is by default, for example
<?php
class ControllerThingyStuff extends Controller {
public function index() {
// This is called with route=thingy/stuff or thingy/stuff/index
}
public function something() {
// This is called with route=thingy/stuff/something
}
}

Categories