php error calling an abstract class - php

I get this error with the ATK 9 framework
class App\Modules\Auth\Module contains 1 abstract method and must therefore be declared abstract or implement the remaining methods
calling the below class:
abstract class Module
{
public static $module;
/** #var Atk $atk */
private $atk;
/** #var Menu $menu */
private $menu;
public function __construct(Atk $atk, Menu $menu)
{
$this->atk = $atk;
$this->menu = $menu;
}
protected function getMenu()
{
return $this->menu;
}
protected function getAtk()
{
return $this->atk;
}
abstract public function register();
public function boot()
{
//noop
}
public function registerNode($nodeName, $nodeClass, $actions = null)
{
$this->atk->registerNode(static::$module.'.'.$nodeName, $nodeClass, $actions);
}
public function addNodeToMenu($menuName, $nodeName, $action, $parent = 'main', $enable = null, $order = 0, $navbar = 'left')
{
if ($enable === null) {
$enable = [static::$module.'.'.$nodeName, $action];
}
$this->menu->addMenuItem($menuName, Tools::dispatch_url(static::$module.'.'.$nodeName, $action), $parent, $enable, $order, static::$module, '', $navbar);
}
public function addMenuItem($name = '', $url = '', $parent = 'main', $enable = 1)
{
$this->menu->addMenuItem($name, $url, $parent, $enable, 0, static::$module);
}
}
this is the code i use to call the class Module:
class Module extends \Sintattica\Atk\Core\Module
{
static $module = 'auth';
public function boot()
{
$this->registerNode('users', Users::class, ['admin', 'add', 'edit', 'delete']);
$this->registerNode('groups', Groups::class, ['admin', 'add', 'edit', 'delete']);
$this->registerNode('users_groups', UsersGroups::class);
$this->addMenuItem('auth');
$this->addNodeToMenu('users', 'users', 'admin', 'auth');
$this->addNodeToMenu('groups', 'groups', 'admin', 'auth');
}
}
thanks

You HAVE TO implement register method from \Sintattica\Atk\Core\Module Class in your Client Module Class.
When extending an Abstract class, ALL Abstract methods MUST be implemented in client(child class) code.

Related

Silverstripe 4 Undefined index: Subscribe

I create a form like this link but when I try to submit these error shows to me
1- how to extend these form to all classes {pages} (I try it in Page & PageController and the form is repeating in my all other pages class)
2- how to fix these errors?
Page.php:
<?php
namespace {
use SilverStripe\CMS\Model\SiteTree;
use project\Subscribe;
class Page extends SiteTree
{
private static $has_many = [
'Subscribes' => Subscribe::class,
];
}
}
PageController.php:
<?php
namespace {
use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\EmailField;
use SilverStripe\Forms\TextareaField;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\RequiredFields;
use project\Subscribe;
class PageController extends ContentController
{
private static $allowed_actions = [
'EmailForm',
];
public function EmailForm()
{
$form = Form::create(
$this,
__FUNCTION__,
FieldList::create(
EmailField::create('Email',''),
),
FieldList::create(
FormAction::create('handleSubscribe','Submit')
->setUseButtonTag(true)
->addExtraClass('button')
),
RequiredFields::create('Email')
)
->addExtraClass('input-group');
foreach($form->Fields() as $field) {
$field->addExtraClass('form-control')
->setAttribute('placeholder', $field->getName().'*');
}
foreach($form->Fields() as $field) {
$field->addExtraClass('form-control')
->setAttribute('placeholder', $field->getName().'*');
}
$data = $this->getRequest()->getSession()->get("FormData.{$form->getName()}.data");
return $data ? $form->loadDataFrom($data) : $form;
}
public function handleSubscribe($data, $form)
{
$session = $this->getRequest()->getSession();
$session->set("FormData.{$form->getName()}.data", $data);
$existing = $this->Subscribes()->filter([
'Subscribe' => $data['Subscribe']
]);
if($existing->exists()) {
$form->sessionMessage('That Email already exists! Spammer!','bad');
return $this->redirectBack();
}
$subscribe = Subscribe::create();
$subscribe->PageID = $this->ID;
$form->saveInto($subscribe);
$subscribe->write();
$session->clear("FormData.{$form->getName()}.data");
$form->sessionMessage('Thanks for your comment!','good');
return $this->redirectBack();
}
}
}
Suscribe.php:
<?php
namespace projet;
use SilverStripe\ORM\DataObject;
use SilverStripe\Forms\FieldList;
class Subscribe extends DataObject
{
private static $singular_name = 'Subscribe';
private static $table_name = 'Subscribe';
private static $db = [
'Email' => 'Varchar(100)',
];
private static $has_one = [
'Page' => Page::class,
'Home' => Home::class,
];
private static $summary_fields = array(
'Email' => 'Email',
);
}
Home.php:
<?php
namespace project;
use Page;
use PageController;
class Home extends Page {
private static $singular_name = 'Home';
private static $description = 'Index Page';
private static $table_name = 'Home';
private static $icon = 'app/icon/home.png';
private static $has_many = [
'Subscribes' => Subscribe::class,
];
}
class HomeController extends PageController {
}
How to extend fix the Non-duplicate data & extends to the whole project?

Yii2 save() creating DB row with default values

I am trying to implement a login method using OpenID, and the $_SESSION var's are posting correctly - and through those I am simply trying to register users in MySQL. For some reason, when passing through the 'login' action in my controller ::
public function actionLogin()
{
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}
include ('../views/user-record/steamauth/userInfo.php');
$steamid = $_SESSION['steam_steamid'];
$username = $_SESSION['steam_personaname'];
$profileurl = $_SESSION['steam_profileurl'];
$avatar = $_SESSION['steam_avatar'];
$avatarmedium = $_SESSION['steam_avatarmedium'];
$avatarfull = $_SESSION['steam_avatarfull'];
$user = UserRecord::findBySteamId($steamid);
if ($user === null)
{
$user = new UserRecord();
$user->steamid = $steamid;
$user->username = $username;
$user->profileurl = $profileurl;
$user->avatar = $avatar;
$user->avatarmedium = $avatarmedium;
$user->avatarfull = $avatarfull;
$user->verified = 0;
$user->banned = 0;
$user->save();
}
Yii::$app->user->login($user, 604800);
return $this->redirect(Yii::$app->user->returnUrl);
}
EDIT: Here is the UserRecord class, forgot to add it in.
<?php
namespace app\models;
class UserRecord extends \yii\db\ActiveRecord implements \yii\web\IdentityInterface
{
public $id;
public $steamid;
public $username;
public $profileurl;
public $avatar;
public $avatarmedium;
public $avatarfull;
public $verified;
public $banned;
public $rank;
public $authKey;
// public $password;
// public $accessToken;
public static function tableName()
{
return 'users';
}
public function getAuthKey()
{
return $this->authKey;
}
public function getId()
{
return $this->id;
}
public function validateAuthKey($authKey)
{
return $this->authKey === $authKey;
}
public static function findIdentity($id)
{
return self::findOne($id);
}
public function validateSteamID($steamid)
{
return $this->steamid === $steamid;
}
public static function findIdentityByAccessToken($token, $type = null)
{
throw new \yii\base\NotSupportedException;
}
public static function findBySteamId($steamid)
{
return self::findOne(['steamid' => $steamid]);
}
}
The result is simply a posted row, with none of the data entered.
Any help would be greatly appreciated, thank you.
If you have redefine the same columns name using public vars these override the vars for activeRecord and then are saved only empty value ..
if this you must remove the (redifined) public vars in your model
otherwise if you have no rules then
Try adding safe at the attribute in you model rules
public function rules()
{
return [
[['steamid', 'username', 'profileurl', 'avatar', 'avatarmedium',
'avatarfull', 'verified', 'banned', 'rank', 'authKey',], 'safe'],
];
}
Declaring 'public' variables made the save() ignore the data being posted. Thanks.

How do I get the current controller in a Laravel 5.2 Service Provider boot or register method?

I've got a little problem on my hands. I can't manage to get the current controller name from the request in a Service Provider.
I want to dynamically provide a different repository by typehinting the same interface based on the controller I'm currently in.
My current service provider looks something like this, but the request()->route() returns null.
private $currentController;
private static $controllerBindings = [
'FooController' => ['RepositoryInterface' => 'FooRepository'],
];
private static $bindings = [
'SomeInterface' => 'SomeRepository'
];
public function boot()
{
$controller = request()->route()->getAction()['controller'];
$controller = preg_replace('/#[a-zA-Z0-9]+/', '', $controller);
$this->currentController = $controller;
}
public function register()
{
if ( array_key_exists($this->currentController, self::$controllerBindings) ) {
foreach (self::$controllerBindings[$this->currentController] as $interface => $dependency) {
app()->bind($interface, $dependency);
}
}
else {
foreach (self::$bindings as $interface => $dependency) {
app()->bind($interface, $dependency);
}
}
}
I've tried doing this and it gives: BindingResolutionException in Container.php line 748:
Target [App\Business\Interfaces\RepositoryInterface] is not instantiable while building [App\Http\Controllers\Admin\SettingsController].
private static $bindings = [
'App\Http\Controllers\SettingsController' => [
'App\Business\Interfaces\RepositoryInterface' => 'App\Business\Admin\Repositories\SettingsRepository',
],
];
public function boot()
{
}
public function register()
{
foreach (self::$bindings as $entity => $binding) {
if ( is_array($binding) ) {
$this->bindEntityFromArray($entity, $binding);
}
else {
app()->bind($entity, $binding);
}
}
}
private function bindEntityFromArray($entity, array $bindings)
{
foreach ($bindings as $interface => $dependency) {
app()->when($entity)->needs($interface)->give($dependency);
}
}
I inject the RepositoryInterface into the Controller's constructor.

Laravel send default variables to layout

Having the following class that is extended by other controllers
class Admin_Controller extends Base_Controller
{
static $admin_layout = 'admin.layouts.default';
public function __construct()
{
parent::__construct();
$role_object = User::find(Auth::user()->id)->roles()->get();
$role = $role_object[0]->attributes['name'];
such as:
class Admin_Draws_Controller extends Admin_Controller
{
public $restful = true;
public function __construct()
{
$this->layout = parent::$admin_layout;
parent::__construct();
}
public function get_index()
{
$view = View::make('admin.templates.draws');
$this->layout->content = $view;
}
}
How can I send the $role variable to admin.layouts.default so I can have it when ever the view is loaded?
The point of "global" $role variable is to avoid to have to call it in all of my View::make() like the following:
$view = View::make('admin.templates.articles',
array(
'fields' => $fields,
'data' => $results,
'links' => $links,
'role' => 'role here'. // I don't want to add this where ever I call the View::make
)
);
$this->layout->content = $view;
and just do an echo $role like, in my header.blade.php
I ended up doing the following, which works.
Controller
// Example of variable to set
$this->layout->body_class = 'user-register';
$view = View::make('modules.user.register', array(
'success' => true,
));
$this->layout->content = $view;
My default.layout.php view
<body class="<?php echo isset($body_class) ? $body_class : '' ;?>">
#include('partials.header')
{{ $content }}
#include('partials.footer')
The variable, can be easily used in any other context within the view.

Problem loading models with modules in Zend Framework

I have a folder structure like this and I'm trying to load the News model inside my controller:
<?php
/**
* Login
*/
class Admin_NewsController extends Zend_Controller_Action {
public function preDispatch() {
$layout = Zend_Layout::getMvcInstance();
$layout->setLayout('admin');
}
public function init() {
$this->db = new Application_Admin_Model_DbTable_News();
}
public function indexAction() {
}
public function addAction() {
//$this->getHelper('viewRenderer')->setNoRender();
// Calls the Request object
$request = $this->getRequest();
if ($request->isPost()) {
// Retrieves form data
$data = array(
"new_title" => $request->getParam('txtTitle'),
"new_text" => htmlentities($request->getParam('txtNews')),
"new_image" => $request->getParam('upName'),
"new_published" => 1
);
// Inserts in the database
if ($this->db->addNews($data)) {
$this->view->output = 1;
} else {
$this->view->output = 0;
}
} else {
$this->view->output = 0;
}
$this->_helper->layout->disableLayout();
}
}
And my model:
<?php
class Application_Admin_Model_DbTable_News extends Zend_Db_Table_Abstract
{
protected $_name = 'news';
public function addNews($data) {
$this->insert($data);
}
}
Althoug I'm getting this error:
Since your News class belongs to the module, its name should be Admin_Model_DbTable_News, without Application_ prefix.
See more on autoloading within modules at http://framework.zend.com/manual/en/zend.loader.autoloader-resource.html#zend.loader.autoloader-resource.module

Categories