I downloaded Netbeans and CodeIgniter, and I downloaded 2 plugins for Netbeans. On of them is called "PHP CI Framework" and I can't install it.
When I try to install it I get this message:
The plugin php apis is requested in implementation version 201107282000.
The following plugin is effected:
PHP CI Framework
What other plugin do I need to install for CI to be fully integrated so that I will have full Intellisense and documentation support in Netbeans?
If you just want auto-complete of functions then this will do it for you.
1) Create a folder in Netbeans called 'autocomplete' in 'Source Files'
2) Create two files in here called something like ci_code_completion_controllers.php and ci_code_completion_models.php
Add this into each file;
<?php
/**
********* CONTROLLERS *********
* #property CI_DB_active_record $db
* #property CI_DB_forge $dbforge
* #property CI_Benchmark $benchmark
* #property CI_Calendar $calendar
* #property CI_Cart $cart
* #property CI_Config $config
* #property CI_Controller $controller
* #property CI_Email $email
* #property CI_Encrypt $encrypt
* #property CI_Exceptions $exceptions
* #property CI_Form_validation $form_validation
* #property CI_Ftp $ftp
* #property CI_Hooks $hooks
* #property CI_Image_lib $image_lib
* #property CI_Input $input
* #property CI_Language $language
* #property CI_Loader $load
* #property CI_Log $log
* #property CI_Model $model
* #property CI_Output $output
* #property CI_Pagination $pagination
* #property CI_Parser $parser
* #property CI_Profiler $profiler
* #property CI_Router $router
* #property CI_Session $session
* #property CI_Security $security
* #property CI_Sha1 $sha1
* #property CI_Table $table
* #property CI_Template $template
* #property CI_Trackback $trackback
* #property CI_Typography $typography
* #property CI_Unit_test $unit_test
* #property CI_Upload $upload
* #property CI_URI $uri
* #property CI_User_agent $agent
* #property CI_Validation $validation
* #property CI_Xmlrpc $xmlrpc
* #property CI_Xmlrpcs $xmlrpcs
* #property CI_Zip $zip
* #property Image_Upload $image_upload
* #property Lang_Detect $lang_detect
********* MODELS *********
* #property User_model $user_model
*/
Class CI_Controller {
}
?>
Note: populate the Models section with your own.
3) Goto to the properties of your project in Netbeans and goto the 'PHP Include Path' setting.
Add the autocomplete folder to the path.
4) So now in your controllers/model try typing $this->load-> and hit Ctrl+spacebar, you should see a list of avaiable functions.
For NetBeans 8.1+
Goto:
https://github.com/nbphpcouncil/nb-ci-plugin/releases
Download NB CI Plugins (latest release):
org-nbphpcouncil-modules-php-ci-0.5.1.nbm
org-nbphpcouncil-modules-php-ci-repository-0.5.1.nbm
Install Plugins:
Tools >> Plugins >> Downloaded (tab) >> Add Plugins... >> (browse those downloaded files in your local directory) >> Open >> Install >> Restart NB
Activate CI Framework:
Tools >> Options >> PHP >> Frameworks & Tools (tab) >> select CodeIgniter >> Base Files >> Add Zip... >> now type a name and browse for CodeIgniter’s zip file you downloaded >> OK >> OK >> Restart NB
All Done. :)
Activate CI framework in existing project:
Select your project >> Right click >> Properties >> Expand Frameworks >> select CodeIgniter >> tick on Enabled >> OK (Now you'll see a CI logo followed by your project name)
hope you are using the version of 7.1.2 better use the 7.1.1 so that you can avoid these kind of error it worked for me or better to use same version plugin for the same IDE of netbeans you are using
I just followed this steps:
Download CodeIgniter.3.X.X.zip
Unzip the content into the root of your PHP project in Netbeans file structure with codeIgniter
Run your project, you will see the Welcome page from CodeIgniter
Related
I'm building REST API authentication using Laravel sanctum, I wanna make the user can login in multiple device and it is limited by 2 devices, let's say User A and User B are logged in when the user C log in, the user A is logged out and so on. How to achieve this and what is the concept?
Usually I make a login api when the email and password are correct then return the token.
I've learned this from netflix which is it has limited device to watch movie.
You can simply check how many tokens you've issued to this user from within your personal_access_tokens table, as shown below:
So just run such query when you are signing in the user just before issueing a new token for them:
$issuedTokens = PersonalAccessToken::where('tokenable_type', User::class)
->where('tokenable_id', $userId)
->get();
if ($issuedTokens->count() > 1) {
$returnMessage = 'You have to remove on of the following devices:';
$deviceNames = $issuedTokens->pluck('name')->toArray();
}
// Things are fine, proceed
And if you would like to enhance things even further you might want to extend the PersonalAccessToken model by adding the mobile details of the person who is entering and perhaps their country/city of access.
To extend it, add migration & model files like the following:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
// Remember to change this line, if you wish, back to the old way.
return new class extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('personal_access_tokens', function (Blueprint $table) {
$table->id();
$table->morphs('tokenable');
$table->string('name');
$table->string('token', 64)->unique();
$table->string('country_name')->nullable();
$table->text('abilities')->nullable();
$table->json('mobile_app_details')->nullable();
$table->timestamp('last_used_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('personal_access_tokens');
}
};
And your model:
<?php
namespace App\Models;
use Eloquent;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
use Laravel\Sanctum\PersonalAccessToken as PersonalAccessTokenAlias;
/**
* App\Models\PersonalAccessToken
*
* #property int $id
* #property string $tokenable_type
* #property int $tokenable_id
* #property string $name
* #property string $token
* #property array|null $abilities
* #property object|null $mobile_app_details
* #property string|null $country_name
* #property Carbon|null $last_used_at
* #property Carbon|null $created_at
* #property Carbon|null $updated_at
* #property-read Model|\Eloquent $tokenable
* #method static Builder|PersonalAccessToken newModelQuery()
* #method static Builder|PersonalAccessToken newQuery()
* #method static Builder|PersonalAccessToken query()
* #method static Builder|PersonalAccessToken whereAbilities($value)
* #method static Builder|PersonalAccessToken whereCreatedAt($value)
* #method static Builder|PersonalAccessToken whereId($value)
* #method static Builder|PersonalAccessToken whereLastUsedAt($value)
* #method static Builder|PersonalAccessToken whereMobileAppDetails($value)
* #method static Builder|PersonalAccessToken whereName($value)
* #method static Builder|PersonalAccessToken whereToken($value)
* #method static Builder|PersonalAccessToken whereTokenableId($value)
* #method static Builder|PersonalAccessToken whereTokenableType($value)
* #method static Builder|PersonalAccessToken whereUpdatedAt($value)
* #mixin Eloquent
* #noinspection PhpFullyQualifiedNameUsageInspection
* #noinspection PhpUnnecessaryFullyQualifiedNameInspection
*/
class PersonalAccessToken extends PersonalAccessTokenAlias
{
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'name',
'token',
'abilities',
'mobile_app_details',
'country_name',
];
protected $casts = [
'abilities' => 'json',
'last_used_at' => 'datetime',
'mobile_app_details' => 'object'
];
}
One last important step is to tell Laravel to ignore original migrations and to load the custom model, so in your AppServiceProvider:
<?php
namespace App\Providers;
use App\Models\PersonalAccessToken;
use Illuminate\Support\ServiceProvider;
use Laravel\Sanctum\Sanctum;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* #return void
*/
public function register()
{
Sanctum::ignoreMigrations();
// other lines go here
}
/**
* Bootstrap any application services.
*
* #return void
*/
public function boot()
{
Sanctum::usePersonalAccessTokenModel(PersonalAccessToken::class);
// other lines go here
}
}
hello family I am working on a school management project but I have a problem with relations:
I have a table of years, students, level
now a pupil can register only once in a level during a school year,
during a school year several pupils can register for a level
table eleves belongToMany table niveaux
table niveau belongToMany table eleves
table eleve_niveau belongTo table annees
table annees has many eleve_niveau
Now at the level of my models I made his:
model annee
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
/**
* #property integer $id
* #property string $debut_annee
* #property string $fin_annee
* #property string $annee_scolaire
* #property string $created_at
* #property string $updated_at
* #property EleveNiveau[] $eleveNiveaus
* #property Niveau[] $niveauxes
*/
class Annee extends Model
{
/**
* The "type" of the auto-incrementing ID.
*
* #var string
*/
protected $keyType = 'integer';
/**
* #var array
*/
protected $fillable = ['debut_annee', 'fin_annee', 'annee_scolaire', 'created_at', 'updated_at'];
/**
* #return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function eleveNiveaus()
{
return $this->hasMany('App\EleveNiveau');
}
/**
* #return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function niveauxes()
{
return $this->hasMany('App\Niveau');
}
}
model niveau
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
/**
* #property integer $id
* #property integer $annee_id
* #property string $nom_niveau
* #property string $branche
* #property string $created_at
* #property string $updated_at
* #property Annee $annee
* #property EleveNiveau[] $eleveNiveaus
*/
class Niveau extends Model
{
/**
* The "type" of the auto-incrementing ID.
*
* #var string
*/
protected $keyType = 'integer';
/**
* #var array
*/
protected $fillable = ['annee_id', 'nom_niveau', 'branche', 'created_at', 'updated_at'];
/**
* #return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function annee()
{
return $this->belongsTo('App\Annee');
}
/**
* #return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function eleveNiveaus()
{
return $this->hasMany('App\EleveNiveau');
}
}
model eleves
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
/**
* #property integer $id
* #property string $pv
* #property string $nom
* #property string $prenom
* #property string $created_at
* #property string $updated_at
* #property EleveNiveau[] $eleveNiveaus
*/
class Eleve extends Model
{
/**
* The "type" of the auto-incrementing ID.
*
* #var string
*/
protected $keyType = 'integer';
/**
* #var array
*/
protected $fillable = ['pv', 'nom', 'prenom', 'created_at', 'updated_at'];
/**
* #return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function eleveNiveaus()
{
return $this->hasMany('App\EleveNiveau', 'eleve_id');
}
}
I did a model for the pivot table
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
/**
* #property integer $eleve_id
* #property integer $niveau_id
* #property integer $annee_id
* #property string $date_inscription
* #property string $created_at
* #property string $updated_at
* #property Annee $annee
* #property Elefe $elefe
* #property Niveau $niveau
*/
class EleveNiveau extends Model
{
/**
* The table associated with the model.
*
* #var string
*/
protected $table = 'eleve_niveau';
/**
* #var array
*/
protected $fillable = ['date_inscription', 'created_at', 'updated_at'];
/**
* #return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function annee()
{
return $this->belongsTo('App\Annee');
}
/**
* #return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function elefe()
{
return $this->belongsTo('App\Elefe', 'eleve_id');
}
/**
* #return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function niveau()
{
return $this->belongsTo('App\Niveau');
}
}
the problem I can't manage to insert into the pivot table I don't know which model to start with
if I use the high model to register a pupil at a level, I have to go through the pivot model
is there a possibility ????
Did you reed the documentaion? Which version of laravel are you using?
I use version 7 in laravel
I read the laravel documentation I found an attached method so at the level of my models I went
the foreign key attribute has my two models
hasMany('App\EleveNiveau', 'eleve_id');
// }
public function niveaux()
{
return $this->belongsToMany(Niveau::class)->withPivot('annee_id');
}
}
belongsTo('App\Annee');
}
/**
* #return \Illuminate\Database\Eloquent\Relations\HasMany
*/
// public function eleveNiveaus()
// {
// return $this->hasMany('App\EleveNiveau');
// }
public function eleves()
{
return $this->belongsToMany(Eleve::class)->withPivot('annee_id');
}
}
I think it works now there is another method to manage a pivot table which contains 3 secondary keys
I use laravel-admin (https://laravel-admin.org) in my laravel project. I wish to show on User admin panel role names of user. But I get error message:
SQLSTATE[42703]: Undefined column: 7 ERROR: column users_roles.role___id does not exist LINE 1: ...les" inner join "users_roles" on "roles"."__id" = "users_rol... ^ (SQL: select "roles".*, "users_roles"."user___id" as "pivot_user___id", "users_roles"."role___id" as "pivot_role___id" from "roles" inner join "users_roles" on "roles"."__id" = "users_roles"."role___id" where "users_roles"."user___id" in (1, 2, 3))
Here are my classes and controller:
User.php:
namespace App\Models;
/**
* Class User
* #package App\Models
*
* #property integer $__id
* #property string $email
* #property string $password
* #property string|null $firstname
* #property string|null $lastname
* #property \DateTime|null $visited_at
* #property string|null $phone
* #property string|null $avatar
* #property string|null $remember_token
* #property \DateTime $created_at
* #property \DateTime $updated_at
*/
class User extends Authenticatable
{
use Notifiable;
protected $primaryKey = '__id';
public function roles() :BelongsToMany
{
return $this->belongsToMany(Role::class,'users_roles');
}
}
Role.php:
<?php
namespace App\Models;
/**
* Class Role
* #package App\Models
*
* #property integer $__id
* #property string $key
* #property string $name
*/
class Role extends Model
{
protected $primaryKey = '__id';
public function users(): BelongsToMany
{
return $this->belongsToMany(User::class,'users_roles');
}
}
UserController.php:
<?php
namespace App\Admin\Controllers;
class UserController extends AdminController
{
protected $title = 'User';
protected function grid()
{
$grid = new Grid(new User());
$grid->column('__id', __(' id'));
$grid->column('email', __('Email'));
$grid->column('password', __('Password'));
$grid->column('firstname', __('Firstname'));
$grid->column('lastname', __('Lastname'));
$grid->roles()->display(function($roles) {
$roles = array_map(function ($role) {
return "<span class='label label-success'>{$role['name']}</span>";
}, $roles);
return join(' ', $roles);
});
.......
.........
}
Pivot table users_roles:
create table if not exists users_roles
(
__user_id bigint not null
constraint users_roles___user_id_foreign
references users,
__role_id bigint not null
constraint users_roles___role_id_foreign
references roles,
become_at timestamp(0) not null,
left_at timestamp(0)
);
I have noticed that name of column __role_id the pivot table is transformed in the query as role___id (as error message tells me: "ERROR: column users_roles.role___id"). How to solve this problem?
I had to make some correction:
public function roles() :BelongsToMany
{
return $this->belongsToMany(Role::class,'users_roles',
'__user_id','__role_id');
}
and error message disappeared.
could you help me with the next problem I have, I give you details of what I have so far:
I have 3 models, with a One to Many relationship:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Province;
/**
* Class Currency
*
* #property $id
* #property $abbreviation
* #property $description
* #property $active
* #property $created_at
* #property $updated_at
*
* #package App
* #mixin \Illuminate\Database\Eloquent\Builder
*/
class Country extends Model
{
/**
* Attributes that should be mass-assignable.
*
* #var array
*/
protected $fillable = ['name','abbreviation','active'];
public function provinces()
{
return $this->hasMany(Province::class);
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Country;
use App\Models\Entity;
/**
* Class Province
*
* #property $id
* #property $name
* #property $active
* #property $created_at
* #property $updated_at
*
* #package App
* #mixin \Illuminate\Database\Eloquent\Builder
*/
class Province extends Model
{
/**
* Attributes that should be mass-assignable.
*
* #var array
*/
protected $fillable = ['name', 'country_id', 'active'];
public function country()
{
return $this->belongsTo(Country::class);
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Province;
class Entity extends Model
{
/**
* Attributes that should be mass-assignable.
*
* #var array
*/
protected $fillable = ['name', 'province_id', 'active'];
public function province()
{
return $this->belongsTo(Province::class);
}
}
I want to show in a view with Blade a select with grouped options, in this case:
-- Country 1
-- Province 1
-- Province 2
-- Province 3
-- Country 2
-- Province 1
-- Province 2
-- Province 3
I am passing the $provinces variable in sight with Blade as follows:
public function edit($id)
{
$entity = Entity::find($id);
$provinces = Province::get(['id', 'name', 'country_id'])->groupBy(['country.name', 'name'])->toArray();
return view('entity.edit', [
'entity' => $entity,
'provinces' => $provinces
]);
}
<div class="form-group">
{{ Form::label('Provinces') }}
{!!Form::select('province_id', $provinces, $entity->province->id ?? null, ['class' => 'form-control'])!!}
</div>
but I don't achieve the expected result, I suppose that as I have been reading, the second parameter passed to Form::select must be of the 2-dimensional array type
Please, if you could help me get through eloquent to get all the provinces and group them by countries, to get an array of 2 dimensions as I need it. Thank you very much in advance
Start with a Country rather than Province.
Give this a try:
$countries = Country::with('provinces')->get()->transform(function($country) {
return [$country->name => $country->provinces->pluck('name','id')];
});
This should return a structure like this:
"Country 1" =>
1 => "Province 1"
2 => "Province 2"
3 => "Province 3"
N.B. This may require a little bit of refactoring as I haven't been able to run this yet!
While there are many answers on how to get PhpStorm to recognize the CodeIgniter 2.x core functions, I can not figure out how to get it to recognize the CodeIgniter 3.0 database functions.
I have an autocomplete.php file in my config directory that works great for CodeIgniter 2.x (and most of v3.0). Since v3 removed the active record class, the DB functions are no longer recognized.
// help IDE(s) support Codeigniter 2.0
* #property CI_DB_active_record $db <-- no longer valid.
...
*/
How can I get PhpStorm autocomplete working with the new CI v3 DB class?
Update: Here is my autocomplete.php file:
<?php
// help IDE(s) support Codeigniter 2.0
/**
* #property CI_DB_query_builder $db
* #property CI_DB_forge $dbforge
* #property CI_Benchmark $benchmark
* #property CI_Calendar $calendar
* #property CI_Cart $cart
* #property CI_Config $config
* #property CI_Controller $controller
* #property CI_Email $email
* #property CI_Encrypt $encrypt
* #property CI_Exceptions $exceptions
* #property CI_Form_validation $form_validation
* #property CI_Ftp $ftp
* #property CI_Hooks $hooks
* #property CI_Image_lib $image_lib
* #property CI_Input $input
* #property CI_Language $language
* #property CI_Loader $load
* #property CI_Log $log
* #property CI_Model $model
* #property CI_Output $output
* #property CI_Pagination $pagination
* #property CI_Parser $parser
* #property CI_Profiler $profiler
* #property CI_Router $router
* #property CI_Session $session
* #property CI_Sha1 $sha1
* #property CI_Table $table
* #property CI_Trackback $trackback
* #property CI_Typography $typography
* #property CI_Unit_test $unit_test
* #property CI_Upload $upload
* #property CI_URI $uri
* #property CI_User_agent $user_agent
* #property CI_Validation $validation
* #property CI_Xmlrpc $xmlrpc
* #property CI_Xmlrpcs $xmlrpcs
* #property CI_Zip $zip
*
*
*
* These are samples entries to make my own functions work. Remove these and add you custom ones.
* #property Tank_auth $tank_auth
* #property Users_model $users_model
* #property Firms_model $firms_model
* #property Event_types_model $event_types_model
* #property Files_model $files_model
* #property Milestones_model $milestones_model
*
*
*/
class CI_Controller {}; class MY_Controller extends CI_Controller {}; class Welcome extends MY_Controller {}; class Admin_Controller extends MY_Controller {}; class CI_Model {}; class MY_Model extends CI_Model {};/**
* #property CI_DB_query_builder $db
* #property CI_DB_forge $dbforge
* #property CI_Config $config
* #property CI_Loader $load
* #property CI_Session $session
*/
// class CI_Model {};
/* End of file autocomplete.php */
/* Location: ./application/config/autocomplete.php */
In a controller, $this->db->where(); is recognized and a command click takes me to the source of that function. However, $query->num_rows() gives a "Cannot find a declaration to go to" error when clicked.
In a Model, none of the CI DB functions are recognized.
Download gist file from https://gist.github.com/topdown/1697338
Put it in the root of your CodeIgniter project (where the index.php is).
In PhpStorm's Project View panel, go to (expand) system/core/
Right click on Controller.php and choose Mark as Plain Text
Do the same for Model.php
I am using PhpStorm 9 may this help.
It is very simple to do with the following steps:-
Create and put phpstorm.php file in the root of your CodeIgniter project.
In PhpStorm’s Project View panel, go to (expand) system/core/.
Right click on Controller.php and choose Mark as Plain Text.
Do the same for Model.php for the model navigation .