Trying to figure out why something like the below cant work. There is a tab in the preferences admin section that points to this controller but when going to it it always output a blank page. I have tried several things but the below is basically what I need. There is no MODEL... I simply need this to get the uploaded file for postProcessing...
The controller file...
class AdminAstroImporterController extends ModuleAdminController {
public function initContent() {
parent::initContent();
return $this->display(__FILE__, 'import.tpl');
}
public function postProcess() {
//do something here
}
}
Looks like you can overide the actual content output by doing as shown in the initContent() function shown below. The 'content' in the smarty assign can be any html you generate yourself.
class AstroImporterAdminController extends AdminController {
public function __construct() {
parent::__construct();
//load current settings
$this->data = unserialize(Configuration::get('ASTRO_IMPORTER'));
}
public function initContent() {
parent::initContent();
$this->show_toolbar = false;
$this->context->smarty->assign(array(
'content' => $this->renderSettings().$this->renderForm().$this->displayFields(),
));
}
I found that this works:
public function renderList()
{
global $currentIndex, $cookie;
$smarty = $this->context->smarty;
$smarty->assign('currentIndex', $currentIndex);
return $this->context->smarty->fetch($this->getTemplatePath().'/main.tpl');
}
Although its dirty as hell, it seems cleaner than Amb3rL4nn answer.
In v1.4 it was very easy to create a tab (and easy to find documentation) I wonder why they changed it and didn't supply an docs.
Related
I'm trying to CRUD with livewire and I'm having some troubles.
Here you can see my main controller component.
class Topics extends Component
{
public function index()
{
$topics = Topic::all();
return view('topics.index', ['topics'=>$topics]);
}
public function create()
{
return view('topics.create');
} /* The store function is in a single component as I say after */
public function show(Topic $topic)
{
return view('topics.show', compact('topic'));
}
public function edit(Topic $topic)
{
return view('topics.edit', compact('topic'));
}
public function destroy(Topic $topic)
{
//
}
public function render()
{
return view('livewire.topics');
}
}
At the beginning I would try to regroup all the CRUD functions in one file livewire. But it was impossible for me to use the store function. I needed to create a component only for storing.
Maybe you have a solution for that too? But it's not my main problem here.
As the store function, the update function doesn't work, so I created a component name "edit".
Here is the problem.
I can :
see all my topics in my (topics.index)
see my create form in my livewire component named "store" include on the view (topics.create) and create a topic
see only one topic with the show function on (topics.show)
click on my "edit" button et see my page "edit" in (topics.edit) but when I include my livewire component named "edit" which contains my update form, I can't for example doing this: "$topic->title"
I can't give to this component the information of the topic I clicked on.
$topic variable is unsigned.
How, in your opinion, can I give to this component the information of the topic I want to edit?
I put here the rest of my actual view and controller.
The store component:
class Store extends Component
{
protected $rules = [
'title' => 'required',
'content' => 'required',
];
public $title;
public $content;
public $user_id;
public function store()
{
$this->user_id = auth()->user()->id;
$this->validate();
$topic = Topic::create([
'title' => $this->title,
'content' => $this->content,
'user_id' => $this->user_id,
]);
return redirect()->route('topics.show', $topic->id);
}
public function render()
{
return view('livewire.test');
}
}
The edit controller's component:
class Edit extends Topics
{
public function render()
{
return view('topics.edit');
}
}
As you can see I tried to extend the Topics controller to pass the $topic... but it doesn't work of course.
I tried:
<div>
<livewire:edit :topic="$topic">
</div>
And some other thing.
Thank you for helping me
You need to define the mount function in your Livewire:
class Store extends Component
{
protected $rules = [ ... ];
public $topic = NULL;
public function mount($topic) {
$this->topic = $topic
}
In Livewire components, you use mount() instead of a class constructor __construct() like you may be used to. NB: mount() is only ever called when the component is first mounted and will not be called again even when the component is refreshed or rerendered.
In addition in your case, if you are separating the View model like that you might as well consider to have the Livewire initiate separately. so in Store also add a $listener and then use javascript to load the Livewire...but that is a whole another question and another answer.
My normal web app runs w/o any issue. Then I wanted to experiment with APIs. I enabled Passport since I need api authorization (but at this moment, I rather want to get this thing working and I have no idea whether it is a problem with Passport) and I wanted to get simple json output of specific Product. So far, I was not able to get it working. I'll describe contents of each file and if someone can direct me to find the issue in my code, that would be great.
Resources\Product.php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class Product extends JsonResource
{
public function toArray($request)
{
return parent::toArray($request);
}
}
Providers\AuthServiceProviders.php
public function boot()
{
$this->registerPolicies();
Passport::routes();
}
User.php
class User extends Authenticatable
{
use HasApiTokens, Notifiable;
...
}
ProductController.php
class ProductController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function apiShow(Product $product)
{
return new ProductResource($product);
}
...
}
routes/api.php
Route::get('/products/{product}', 'ProductController#apiShow');
Now if I go to http://localhost/public/products/1, it displays the page as expected. But if I type in http://localhost/public/api/products/1, it will always go to home page which is set to localhost/public in HomeController.
If I modify routes/api.php as:
Route::get('/products/{id}', function($id) {
return Product::find($id);
});
I get the correct json output in the browser.
Hi I have created a controller in which I am setting the template. It is a front controller. The problem I am getting is that the parent theme is not followed in the controller rather I just get another page uniquely all by itself and by the looks of it it is like that the template is not attached to the module. Currently the controller is just basic. I am beginner. I have attached the controller code. The code of my tpl file is also added. I have attached an image to show the problem.I haven't done any changes elsewhere just calling the controller from the module.php file by the link. Thank you in advance.
//controller code
class ExperimentFirstPageModuleFrontController extends ModuleFrontController
{
public $ssl = true;
public function __construct()
{
$this->bootstrap = true;
parent::__construct();
$this->context = Context::getContext();
}
public function initContent()
{
parent::initContent();
$this->context->smarty->assign(array());
$this->setTemplate('module:experiment/views/templates/front/list.tpl');
}
public function setMedia()
{
parent::setMedia();
$this->addjQuery();
}
}
//tpl file
<h>hello</h>
I have create a Test controller using the code in : Create Custom page in Prestashop 1.5.3.1
class MyPageController extends FrontController
{
public $php_self = 'mypage';
public function init() {
parent::init();
}
public function initContent() {
parent::initContent();
die('test!');
}
}
I put it in the /controllers/front/MyPageController.php and it does not work. i get a clean html page.
What am I missing ?
link to custom page : http://www.funtoy.co.il/index.php?controller=MyPage
Edit 1 :
fix the semicolon at $php_self = 'mypage';
Thanks.
yaniv abo
Remove cache/class_index.php to clear the cache.
I am new on Zend Framwork(MVC). I want to crate simple a Form with some HTML control.
I have create one controller IndexController, code are as follows:
<?php
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// action body
/*$this->view->var = 'User Login Page';*/
$form = new Form_Login();
$this->view->form=$form;
}
}
And my Form's code in application/forms/Login.php:
<?php
require_once('Zend/Form.php');
class Form_Login extends Zend_Form
{
public function init()
{
parent::__construct($options);
// the code bellow will create element
$username = $this->CreateElement('text','username');
$username->setLabel("Username:");
// and
$submit= $this->CreateElement("submit","submit");
$submit->setLabel("Submit");
// now add elements to the form as
$this->addElements(array(
$username,
$submit
));
}
}
?>
When i run this project then its show an error like this:
**Fatal error: Class 'Form_Login' not found in C:\xampp\htdocs\LoginForm\application\controllers\IndexController.php on line 16**
Please help me...
Thanks
Pankaj
Everything looks good, make sure your Login.php file has this as the first lines:
<?php
class Form_Login extends Zend_Form
{
public function init()
If that doesn't help, you might want to check your index.php/Bootstrap.php files and server configuration to make sure all paths are correct.