Error displaying page in OpenCart - opencart

Hello I am new in OpenCart and I am studying it now for my next project. And My first step in learning this framework? is to display my own page using a link from my navigation menu in admin area. But I am getting this error.
Notice: Error: Could not load template C:\wamp\www\myshop/admin/view/template/locations/countries_list.tpl! in C:\wamp\www\myshop\system\engine\controller.php on line 90
And I can't spot my error. Here's what I did.
Here's my controller /controller/locations/countries.php
<?php
class ControllerLocationsCountries extends Controller {
private $error = array();
public function index() {
$this->language->load('locations/countries');
$this->document->setTitle($this->language->get('heading_title'));
$this->getList();
}
protected function getList() {
$this->data['heading_title'] = $this->language->get('heading_title');
$this->template = 'locations/countries_list.tpl';
$this->response->setOutput($this->render());
}
}
Here's my simple view /view/template/locations/countries_list.php
<h1>Hello</h1>
Then in my header I include this code for displaying a link in menu navigation /controller/common/header.php
$this->data['text_locations'] = $this->language->get('text_locations');
....
$this->data['locations'] = $this->url->link('locations/countries', 'token=' . $this->session->data['token'], 'SSL');
That's all. I don't know what part is wrong. Can you help me with this?

The error is pretty self explanatory. The template file doesn't exist. Make sure the template filename and path is exactly the same and that you're using .tpl as the extension and not .php. It's also possible there could be a permissions error, but on WAMP that's not likely

Related

Add CMS menu item with fields in Silverstripe 3.6

Still a newbie in Silverstripe. I am experimenting with the CMS and I would like to create a new CMS menu with text fields in it. I managed to add a CMS menu item with a gridfield in it to add data objects but what I require is to have text fields directly inside the CMS menu item without creating a Data Object (similar to the Settings menu as shown in the image below)
Can someone guide me in what I need to extend and how to set the thing up? Many thanks in advance.
You can extend the settings section. The following example adds a tab called Social Media under the settings section and 2 fields FacebookURL and TwitterURL. You can change this to any fields / tabs that you want.
**mysite/_config/extensions.yml
---
Name: mysiteextensions
After: 'framework/*','cms/*'
---
SiteConfig:
extensions:
- SiteConfigDecorator
mysite/code/extensions/SiteConfigDecorator
<?php
class SiteConfigDecorator extends DataExtension {
private static $db = array(
'FacebookURL' => 'Varchar(200)',
'TwitterURL' => 'Varchar(200)'
);
private static $has_one = array(
'FooterQuoteButtonPage' => 'SiteTree'
);
public function updateCMSFields(FieldList $fields) {
$fields->addFieldToTab('Root.SocialMedia', TextField::create('FacebookURL', 'Facebook URL'));
$fields->addFieldToTab('Root.SocialMedia', TextField::create('TwitterURL', 'Twitter URL'));
}
function __construct() {
parent::__construct();
}
}
To access these fields in the templates, you use $SiteConfig.FIELDNAME. In this case it would be $SiteConfig.FacebookURL and $SiteConfig.TwitterURL

Command console to generate a twig template in symfony 4

I keep rereading the symfony 4 documentation to try to generate twig template with the console commands but I did not find a command . Is there any one know a bundle to generate twig template with console commands ?
I'm solved
class SendEmailNotify extends Command
{
private $container;
private $twig;
private $mailer;
public function __construct($name = null, \Psr\Container\ContainerInterface $container, \Swift_Mailer $mailer)
{
parent::__construct($name);
$this->container = $container;
$this->twig = $this->container->get('twig');
$this->mailer = $mailer;
}
I checked it and the sad answer is no. The list of maker commands is available here. You can even make a twig extension, but not a view. It is worth submitting to them I think.
I needed Twig functionality to send emails from my custom console command.
This is the solution I came up with.
First I installed Twig.
composer require "twig/twig:^2.0"
Then created my own twig service.
<?php
# src/Service/Twig.php
namespace App\Service;
use Symfony\Component\HttpKernel\KernelInterface;
class Twig extends \Twig_Environment {
public function __construct(KernelInterface $kernel) {
$loader = new \Twig_Loader_Filesystem($kernel->getProjectDir());
parent::__construct($loader);
}
}
Now my email command looks like this.
<?php
# src/Command/EmailCommand.php
namespace App\Command;
use Symfony\Component\Console\Command\Command,
Symfony\Component\Console\Input\InputInterface,
Symfony\Component\Console\Output\OutputInterface,
App\Service\Twig;
class EmailCommand extends Command {
protected static $defaultName = 'mybot:email';
private $mailer,
$twig;
public function __construct(\Swift_Mailer $mailer, Twig $twig) {
$this->mailer = $mailer;
$this->twig = $twig;
parent::__construct();
}
protected function configure() {
$this->setDescription('Email bot.');
}
protected function execute(InputInterface $input, OutputInterface $output) {
$template = $this->twig->load('templates/email.html.twig');
$message = (new \Swift_Message('Hello Email'))
->setFrom('emailbot#domain.com')
->setTo('someone#somewhere.com')
->setBody(
$template->render(['name' => 'Fabien']),
'text/html'
);
$this->mailer->send($message);
}
}
This instruction will make a Controller without a twig template
php bin/console make:controller --no-template
Surprisingly this instruction will make a Controller and a template file and subdirectory
php bin/console make:controller

ASP .NET MVC - Click on href link and update a table (ActionLink)

I have a partial view with this code:
<a href="http://www.teste.net/#Html.DisplayFor(modelItem =>
Model.Link)">#Html.DisplayFor(modelItem => Model.Titulo)<a>
This render a link in a View so the users can click on link and access the html pages outside application. It works fine.
But I need update a table when a user click in link so I need trigger an Action.
I've tried using this code:
#Html.ActionLink(#Html.DisplayFor(modelItem => Model.Titulo).ToString(), "GetHtmlFile", new { id = Model.ArtigoID , path = #Html.DisplayFor(modelItem => Model.Link) })
so the Action GetHtmlFile will need render html files in this way:
public ActionResult GetHtmlPage(int id, string path)
{
updateTableArticle(id);
return new FilePathResult(path, "text/html");
}
It works, but there's a problem. The html files are in relative path so many pictures aren't shown and many links are broken...
There is no easier way to click on the link and update the table in this cenario whithout must render the html files as a view ?

Rest API Web Service - iOS

Its my first time to use web service in iOS.
REST was my first choice and I use code igniter to form it.
I have my Controller:
require APPPATH.'/libraries/REST_Controller.php';
class Sample extends REST_Controller
{
function example_get()
{
$this->load->helper('arh');
$this->load->model('users');
$users_array = array();
$users = $this->users->get_all_users();
foreach($users as $user){
$new_array = array(
'id'=>$user->id ,
'name'=>$user->name,
'age'=>$user->age,
);
array_push( $users_array, $new_array);
}
$data['users'] = $users_array;
if($data)
{
$this->response($data, 200);
}
}
function user_put()
{
$this->load->model('users');
$this->users->insertAUser();
$message = array('message' => 'ADDED!');
$this->response($message, 200);
}
}
, using my web browser, accessing the URL http://localhost:8888/restApi/index.php/sample/example/format/json really works fine and gives this output:
{"users":[{"id":"1","name":"Porcopio","age":"99"},{"id":"2","name":"Name1","age":"24"},{"id":"3","name":"Porcopio","age":"99"},{"id":"4","name":"Porcopio","age":"99"},{"id":"5","name":"Luna","age":"99"}]}
, this gives me a great output using RKRequest by RestKit in my app.
The problem goes with the put method. This URL :
http://localhost:8888/restApi/index.php/sample/user
always give me an error like this:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<xml>
<status/>
<error>Unknown method.</error>
This is my Users model
<?php
class Users extends CI_Model {
function __construct()
{
parent::__construct();
}
function get_all_users()
{
$this->load->database();
$query = $this->db->get('users');
return $query->result();
}
function insertAUser(){
$this->load->database();
$data = array('name'=> "Sample Name", 'age'=>"99");
$this->db->insert('users', $data);
}
}
?>
What is the work around for my _put method why am I not inserting anything?
Thanks all!
Unless you set the method to PUT or POST, your web server is not going to treat it as such. When you enter URLs in a browser bar, that is almost always a GET request. You might try to use curl like
curl -X POST -d #filename http://your.url.path/whatever
Another link would be: https://superuser.com/questions/149329/what-is-the-curl-command-line-syntax-to-do-a-post-request
So you should be able to do a PUT similarly (perhaps with no data). Not really sure if this should be iOS tagged though :)
I got this problem by using Firefox plug in rest Client.
I just have to indicate the headers and the body to make put and post work.

CakePHP fatal error: Class 'ErrorHandler' not found

I've generated testsuits via "cake bake testsuit" and used localhost/test.php for my app.
So, the is an error when I tried to run one of test (else tests are valid):
Fatal error: Class 'ErrorHandler' not found in Z:\home\prodvigator\www\cake\libs\object.php on line 201
This models and controllers are generated by scaffold and I don't think that an error is in this sources.
Using:
CakePHP 1.3
The latest SimpleTest
In my case, deleting all the files in the folder /app/tmp/cache/persistent solved the problem.
try checking the generated tests for an error that gets written at the top of the file.
sometimes i've been known to find something like this in both model and controller tests.
Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EDT/-4.0/DST' instead in /projectname/cake/console/templates/default/classes/test.ctp on line 22
In my case, the error was:
Fatal error: Uncaught Error: Class 'ErrorHandler' not found in C:\[path]\core\cake\libs\object.php on line 211
( ! ) Error: Class 'ErrorHandler' not found in C:\[path]\core\cake\libs\object.php on line 211
The error was happening to me when trying to visit http://localhost/user_accounts/index
I already had the view created at app\views\user_accounts\index.ctp with the following content:
<div>
Text from div
</div>
I had created the corresponding controller as well at app\controllers\user_accounts_controller.php:
<?php
class UserAccountsController extends AppController {
public function index() {
// Render the view in /views/user_accounts/index.ctp
$this->render();
}
}
?>
Since I was not associating a model to this controller, I was missing this: var $uses = array();. It would have saved me time if the error had been more explicit, something such as "You do not have a model associated to this controller".
The fix was:
<?php
class UserAccountsController extends AppController {
// Use this controller without a need for a corresponding Model file.
var $uses = array();
public function index() {
// Render the view in /views/user_accounts/index.ctp
$this->render();
}
}
?>