Wednesday, April 28, 2010

failed to open stream - joomla

Following error occur on last time article. Now we try to solve this issue ...............
"
Warning: require_once(C:\AppServ\www\Joomla\administrator\components\com_lanka1\controller.php) [function.require-once]: failed to open stream: No such file or directory in C:\AppServ\www\Joomla\administrator\components\com_lanka1\lanka1.php on line 17

Fatal error: require_once() [function.require]: Failed opening required 'C:\AppServ\www\Joomla\administrator\components\com_lanka1\controller.php' (include_path='.;C:\php5\pear') in C:\AppServ\www\Joomla\administrator\components\com_lanka1\lanka1.php on line 17
"

Wt is this error? Yes this is arising due to MVC. Base on MVC structure, our component automatically find "controller.php" file. But at the moment it is not in our com_lanka1 folder.

we can use any name for this. But standard naming is important. see the code of "lanka1.php" can u see

"require_once( JPATH_COMPONENT.DS.'controller.php' );"

code on their? Mmm ... this is the reason arrising above file not found issue.

Following code show the simple syntax of controller.php file


<?php
/**
* Lanka1 default controller
*
* @package Joomla.component
* @subpackage Components
* @link http://inetlanka.com
* @license GNU/GPL
* @auth inetlanka web team - [ info@inetlanka.com / wapnishantha@gmail.com ]
*/

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport('joomla.application.component.controller');

/**
* Lanka1 Component Controller
*
* @package Joomla.component
* @subpackage Components
*/
class Lanka1sController extends JController
{
/**
* Method to display the view
*
* @access public
*/
function display()
{
parent::display();
}
}



Can u guess the essential part of this code? Mmm ...........

yes it is "class Lanka1sController extends JController". Look wt is the text it use. "Lanka1sController" In this word, [ Did u remeber?our component name is com_lanka1 ]. Here we take it as lanka1s. must remember this "S" is very importent. And also our class extend to core joomla class through the "JController"

ok when after adding "controller.php" to our testing component [administrator ->components->com_lanka1->controller.php]. again visit following link, from joomla admin [ http://YOUR JOOMLA PATH/administrator/index.php?option=com_lanka1 ]



Is this the error? yes this is the error we face on this stage.

continue with next lesson

wAp

Saturday, April 24, 2010

Fixing "Component Not Found" - joomla

Ok last time we got following error

let see how to solve this issue. Issue say about "Component Not Found". That means there is no such a component on our code.

ple go folder structure
administrator ->components->com_lanka1

There is only 2 files [index.html / install.xml]. From now, we have to develop MVC structure base coding.

First File you need to add "com_lanka1" folder is "lanka1.php" And code show as follows



<?php
/**
* com_lanka default controller
*
* @package Joomla.component
* @subpackage Components
* @link http://inetlanka.com
* @license GNU/GPL
* @auth inetlanka web team - [ info@inetlanka.com / wapnishantha@gmail.com ]
*/

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

// Require the base controller

require_once( JPATH_COMPONENT.DS.'controller.php' );

// Require specific controller if requested
if($controller = JRequest::getWord('controller')) {
$path = JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php';
if (file_exists($path)) {
require_once $path;
} else {
$controller = '';
}
}

// Create the controller
$classname = 'Lanka1sController'.$controller;
$controller = new $classname( );

// Perform the Request task
$controller->execute( JRequest::getVar( 'task' ) );

// Redirect if set by the controller
$controller->redirect();




then try to again brows
"http://YOUR JOOMLA PATH/administrator/index.php?option=com_lanka1"


It is must, showing above error on your web page. other wise there is another issue on ur code

next time we will fix this issue

wAp