App/Views/Pages/used.ctp cannot be read (CAKEPHP) - php

Good day!
I have a home page wherein there's a menu at the left side part of it. The button's href when clicked will go to a .ctp file called used.ctp under app/views/pages FOLDER
I already considered putting pages_controller.php and app_controller.php in my app/controllers folder but nothing happened.
The header tag inside the used.ctp cannot be read.
Only the static header declared from index.ctp is all i can see while viewing the used.ctp
First, there was a mysterious error that appeared like...
Error: Create the class controller blah blah blah user_controller.php below the file
Something like that.
I fixed it by creating the said used_controller.php
<?php
class UsedController extends AppController {
var $name = 'Used';
}
?>
But upon refreshing the used.ctp
it still appears empty with only the static header on top declared on index.ctp
Please help me. :(
If you want to see the full source code:
Download -> http://www.mediafire.com/?h3sc14gogq9ohtc
THANKS

The users.ctp file needs to go in /View/Users and you need to create a method in the controller to link to that view.
So
<?php
class UsedController extends AppController {
var $name = 'Used';
public function users() {
}
}
?>
I suggest following a tutorial like the following;
http://book.cakephp.org/2.0/en/tutorials-and-examples/blog/blog.html

Related

Yii2 custom widget assets not registering

I'm trying to develop a custom widget, but I've run into a wall. I have some third-party JS/CSS files I need to include, but for whatever reason, Yii2 will not register them. I've followed everything in the Yii2 documentation but seem to get nowhere. My directory structure is as follows:
components
- DildenFeedback.php
- DildenFeedbackAsset.php
- views/
-- feedback.php
- assets/
-- feedback.min.js
-- feedback.min.css
DildenFeedback.php (Widget Class)
<?php
namespace app\components\yii2feedbackwidget;
use Yii;
use yii\base\Widget;
use app\components\yii2feedbackwidget\DildenFeedbackAsset;
class DildenFeedback extends Widget
{
public function run() {
parent::run();
DildenFeedbackAsset::register($this->view);
return $this->render('feedback');
}
}
DildenFeedbackAsset.php (Widget Asset Class)
<?php
namespace app\components\yii2feedbackwidget;
use yii\web\AssetBundle;
class DildenFeedbackAsset extends AssetBundle {
public $sourcePath = 'assets/';
public $css = ['assets/feedback.min.css'];
public $js = ['assets/feedback.min.js'];
public $depends = ['yii\web\JqueryAsset'];
}
Feedback View
?>
<script type="text/javascript">
$.feedback();
</script>
views/layouts/main.php (The main template I was trying to call in)
<?php $this->endBody() ?>
<?php
echo DildenFeedback::widget();
?>
So when I go to inspect the page, feedback.min.js/css are nowhere to be found. The view file is rendered correctly, but my guess is that my AssetBundle is improperly formed. Any help would be much appreciated.
EDIT (From the Yii Debugger Assets):
sourcePath /var/www/public/components/yii2feedbackwidget/assets
basePath /var/www/public/web/assets/7e80049a
baseUrl /assets/7e80049a
css assets/feedback.min.css
js assets/feedback.min.js
depends yii\web\JqueryAsset
EDIT 2
I have tested this on a fresh install of Yii2, and I get the same error.
Well, you should simply correct your sourcePath :
class DildenFeedbackAsset extends AssetBundle {
public $sourcePath = '#app/components/assets/';
public $css = ['feedback.min.css'];
public $js = ['feedback.min.js'];
public $depends = ['yii\web\JqueryAsset'];
}
You should also fix your view by using registerJs() instead of a script tag :
$this->registerJs('jQuery.feedback();');
I've solved it, and I feel a bit silly. What it came down to, was the location of the widget call. As I noted in my original question, I was echoing the widget like so:
<?php $this->endBody() ?>
<?php
echo DildenFeedback::widget();
?>
However, I did not pay attention to where that call was. It NEEDS to be before the endBody call
<?php
echo DildenFeedback::widget();
?>
<?php $this->endBody() ?>
This ended up solving the issue. Thanks to Soju for directing me towards the widget call.

Layouts Throwing "Attempt to assign property of non-object" In Laravel 4

In the Layouts folder, I have a layout called signup.blade.php
In my controller, I'm assigning a layout to it like so:
protected $layout = 'layouts.signup';
In a separate folder, named "signup" I have a file called "signup1.blade.php" It contains your typical blade template stuff. It's a section called "content". Before the code I have
#section('content')
and it's got #stop at the end.
My controller looks like this:
public function SignUp()
{
$this->layout->content = View::make('signup.signup1');
}
The frustrating part is that this is working with another layout and controller. I've double checked they're the same, and this one does not work. Any suggestions would be greatly appreciated. Thank you.
So, assuming this controller extends BaseController (it must for $layout to work), the code execution sets $this->layout to View::make($this->layout).
Your error seems to show that $this->layout is not getting set to a View object correctly.
Try to run this and see if $this->layout is an object/class, and if so, what class it is.
public function SignUp()
{
echo gettype($this->layout);
echo get_class($this->layout);
}
Knowing what $this->layout does not get changed into a View object means that the setupLayout() method is either not called or, more likely, not the result of View::make($this->layout) is not a proper view (perhaps it's silently failing for some reason).
The above steps hopefully give you a clue into whats happening there. Perhaps layouts.signup isn't a layout the app is finding?
What do your routes look like?
Change
class UsersController extends Controller
to
class UsersController extends BaseController
Hopefully the author of Confide fixes this :-)

Zend framework, View

Small mystery: can't seem to pass views between my Index controller (chartAction) and my view. When I go to my localhost it is not accessing the view phtml- instead it is just showing the controller every time (i.e: if I write "echo "HELLO WORLD!""; in my controller I get that echoed...but if I do a $this->view->test = "Hello World!" then access the index.phtml and type in echo $this->test; I get nothing (it still defaults to the controller action). Is there a step that I'm missing here? Why is my $this->view not functioning? I used the command line to create the view so I'm pretty sure that should be set up correctly.
Do I need to register something? Thanks for any help!
Assuming a standard MVC setup of ZF1.x, there is a definite relationship between the url, the controller and the action.
The url http://mydomain.com/index would call the index action of the index controller, typically the index action is the default action and is called automatically. the view script would be /application/views/scripts/index/index.phtml
The url http://mydomain.com/index/chart would call the chart action of the index controller and the view script would be /application/views/scripts/index/chart.phtml
Keep in mind that this behavior is changeable based on configuration and routing options.
It sounds like you may be fairly new at working with ZF. So something like the following may help demonstrate the relationship :
// application/controllers/IndexController.php
class IndexController extends Zend_Controller_Action
{
public function init()
{
}
public function indexAction()
{
$this->view->test = "Hello World, from the indexAction().";
}
public function chartAction()
{
$this->view->test = "Hello World, from the chartAction().";
}
// application/views/scripts/index/index.phtml
<?php echo $this->test ?>
// application/views/scripts/index/chart.phtml
<?php echo $this->test ?>
now test your application by calling the url's:
http://yourDomain.com/index/index
http://yourDomain.com/index/chart
If your setup is correct you will see the proper response in your pages.
Case 1: View disabled for just one action:
Look for the following code in your action.
$this->_helper->viewRenderer->setNoRender(true);
Case 2: View disabled for all actions in a specific controller:
Look for the above line in either the init() or preDispatch() functions of the controller.
Case 3: View disabled for all actions in all controllers:
Check case 1 and 2. Also, look for something like the following in your Bootstrap.php:
$frontController->setParam("noViewRenderer", true);
If you find the code like above, you will have to comment it out to get the view working. I am sure there are more possibilities to disable view. Those are to be checked after this.
Your view is disabled..check these lines of code in your action or init of your controller or even the class your controller may be extending
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
UPDATE
You are doing it in your chartAction and echoing in your index.phtml you must do that in your chart.phtml

Putting additional pages on kohana framework

I've started reading kohana documentation but didn't really understand, the index page I need to define in controllers like public $template = "index"; but how do I add other html, php files as links? Because it doesn't find them if I simply put them in the view's folder.
if you need to create a new page first you need to create a function in controller. also you need to assign the view file in that function.
For ex,
Here i ll create a user login page in user controller.
<?php
Class Controller_User extends Controller_Welcome
{
/**For get User Login page**/
public function action_login()
{
$view= View::factory('login');
echo $view;
}
}
?>
login.php file is placed in application/views/login.php
Now your login page is called in the url like http://mysite.com/user/login/
If you want to call the page in a common template file , first you need to assign template file. then you can easily call the page in template file.
For ex,
user.php controller:
<?php
Class Controller_User extends Controller_Welcome
{
/**For get User Login page**/
public function action_login()
{
$this->template='template.php';
$view= View::factory('login');
$this->template->content = $view;
}
}
?>
template.php view file:
-- your html datas here --
<?php
echo new View("header");
?>
-- your html datas here --
<?php
echo $content; ?>
-- your html datas here --
<?php
echo new View("footer");
?>
-- your html datas here --
Here header is header.php, footer is footer.php. all these files are placed in applications/views/ folder.
public $template = "index" means that Controller_Template class will load view from views/index.php file. You can add requred links directly to this file or dynamically - with template variables or subtemplates.
This wiki may help: http://kerkness.ca/kowiki/doku.php

Defining entity in model

I am trying to do a CRUD as mentioned in Jobeet tutorial(http://agiletoolkit.org/learn/tutorial/jobeet/day3). I have also added a generate.php inside page directory with the code mentioned in the link. When I try to access it via browser by http://localhost/atk4.1.2/?page=generate I am getting the following error,
Exception_ForUser
You should call parent::init() when you override it
Additional information:
- object_name: gift_project_generate
- class: page_generate
I also have added a page named crud.php with the following contents inside the page directory the contents of which are as follows,
<?php
class page_crud extends Page{
function init(){
parent::init();
$tabs=$this->add('Tabs');
$tabs->addTab('Gifts')->add('CRUD')->setModel('Gift');
}
}
The following is the Gift.php inside the Model directory,
<?php
class Model_Gift extends Model_Table {
function init(){
parent::init();
$this->addField('id');
$this->addField('name')->type('text');
$this->addField('url')->type('text');
}
}
Now when I try to access the crud page via http://localhost/atk4.1.2/?page=crud, I see the following errors,
Exception_InitError
You should define entity code for Model_Gift
C:\xampp\htdocs\atk4.1.2\atk4\lib\BaseException.php:37
But the database already has a table named gift and $this->dbConnect(); is not commented in Frontend.php.
Am I missing something here?
Add this to your model definition:
public $enity_code='gift';
This should be exactly same as the name of your table in SQL.
The other error you are getting about init() not being called is a bug: https://github.com/atk4/atk4/issues/22

Categories