i need to include vtiger model class for accessing methods and avoid code duplication. i have php file in root . how can i access function in "Vtiger" Model class.
include_once 'vtlib/Vtiger/Utils.php';
require_once('include/database/PearDatabase.php');
require_once 'config.inc.php';
require_once 'includes/Loader.php';
vimport ('includes.runtime.EntryPoint');
global $current_user;
$current_user = Users::getActiveAdminUser();
$obj = new Settings_Newmodel_SyndicateCredential_Model();
Related
For some model, I need to apply a global scope if the logged in user is not super admin. In model's boot() method I tried something like this:
<?php
namespace App;
use Auth;
use App\Scopes\RoleScope;
use Illuminate\Database\Eloquent\Model;
class MyModel extends Model
{
protected static function boot()
{
parent::boot();
if( Auth::check() && ! Auth::user()->isSuperAdmin() ){
static::addGlobalScope(new RoleScope);
}
}
}
The scop never applied! What did I do wrong here? How can I achieve the goal to apply the scope based on the user role? thanks
You cannot access the currently authenticated user in the boot method of the Eloquent model - the Auth middleware hasn't run yet at this point.
What you should do is to perform the super admin check within the apply method of your RoleScope.
I am using Opencart Version 2.1.0.1, how to load frontend model in admin controller,
i have a model function which tells external booking id
class ModelShippingParcelled extends Model {
public function getParcelledBooking($order_id) {
$query = $this->db->query("SELECT booking_id FROM " . DB_PREFIX . "parcelled WHERE order_id = '" . (int)$order_id . "'");
return $query->row;
}
I want to load this model in admin controller. What is the best way to do this?
Should I rewrite this model in admin too? But I don't want to rewrite the same function. If there is a good way please suggest!
Well, there is one ugly trick to achieve what you want. Example if you want to use the frontend's catalog/product model from your admin controller, then you can:
require_once DIR_CATALOG . "model/catalog/product.php";
$product = new ModelCatalogProduct($this->registry);
This will work also when you want to use the admin model from the frontend controller, just change the require statement.
I also needed to call a function from catalog/model inside admin/model (without copying). Requiring a function occured to be imposible in php.
But I figured out that I can move the function into system/library, for example in /system/library/cart/cart.php.
Albeit cart functions is never called in admin it occured to be possible. So I called it like
$this->cart->functionName($params)
To make sure function is still working in catalog I made replacement via shell like
find catalog -type f -print0 | xargs -0 sed -i '' -e 's/this->model_catalog_filter->functionName/this->cart->functionName/g'
I suggest that you make a copy of the model in the admin folder.
And if you are sure which functions you are gonna use copy only them.
Good Day,
I have been using the book of Agile Web Development with Ruby on Rails 4 and I have been trying to use a Model Module in the directory:
app/models/concerns/MyModule.rb
I found some documentation on how to do it for previous versions of rails using the /lib folder and some other methods but I need a simple method to call my Module inside my Model.
Module MyModule
extends ...
#
def some_method_in_MyModule
end
end
I have tried this:
app/models/users.eb
Class ...
include MyModule
a = some_method_in_MyModule
#
end
but rails keeps saying it is not correct.
How do I include a module method in a model with ruby on rails 4?
In previous versions of Rails, we needed to save files in the /lib folder, as we have the new folder app/models/concerns in Rails 4, we can directly call the method from the module in a model without any helper.
e.g:
app/models/concerns/MyModule.rb
Module MyModule
extends .. #
def some_method_in_my_module
end
end
in our model we call it as:
class ...
#
#usuario = MyModule.some_method_in_my_module
#
end
I have a strange issue. Here is the error message:
Call to undefined method MyProject\BlogBundle\Entity\Blog::findOneById()
I have setup the mapping, the entity class was created using the console and I have updated the schema in the database. What could be causing this issue?
I'm using symfony2. Here is the line:
$blogRepo = $this->get('myproject.blog.repository.blog');
$blog = $blogRepo->findOneById($id);
Any ideas?
findOneById doesn't exist, try
$blogRepo->findOneBy(array('id' => $id));
where 'id' is an existing field in your Entity.
You can check the Doctrine's class documentation here: EntityRepository
Edit: looks like findOneById does exist as long as the entity has a field "Id". Check the docs. Thx to Ryall for pointing it out
What is the service definition of myproject.blog.repository.blog? It looks like you are mapping it to MyProject\BlogBundle\Entity\Blog while it really should be MyProject\BlogBundle\Entity\BlogRepository.
Instead of creating your own Repository class you can also have one created on the fly by the EntityManager.
$user = $em->getRepository('MyProject\Domain\User')->find($id);
Or even shorter:
$user = $em->find('MyProject\Domain\User', $id);
Taken from the Doctrine2 ORM Documentation.
try this
$blogRepo = $this->getRepository('myproject.blog.repository.blog');
$blog = $blogRepo->findOneById($id);
getRepository
I have an object which I want to use under admin instead of a model which inherits models.Model. If I make it inherit models.Model, this object will create a table in the database which i don't want. I only want this object to stay in memory.
One solution I have come with help from the nice people at stack overflow is I create admin views, register these custom views via a modelAdmin ( admin.site.register() ) under admin.py and use this model-like object as dynamic data storage (in memory).
Since this model like object doesn't inherit from models.Model, admin.site.register() (under admin.py) doesnt accept it and shows a 'type' object is not iterable" error when I try to access it in the browser.
hmmm. Thanks for your help everyone. The solution I have come up ( with your help ofcourse :) is as follows:
I have two custom templates:
my_model_list.html
my_model_detail.html
Under views.py:
class MyModel(object):
# ... Access other models
# ... process / normalise data
# ... store data
#staff_member_required
def my_model_list_view(request) #show list of all objects
#. . . create objects of MyModel . . .
#. . . call their processing methods . . .
#. . . store in context variable . . .
r = render_to_response('admin/myapp/my_model_list.html', context, RequestContext(request))
return HttpResponse(r)
#staff_member_required
def my_model_detail_view(request, row_id) # Shows one row (all values in the object) in detail
#. . . create object of MyModel . . .
#. . . call it's methods . . .
#. . . store in context variable . . .
r = render_to_response('admin/myapp/my_model_detail.html', context, RequestContext(request))
return HttpResponse(r)
Under the main django urls.py:
urlpatterns = patterns(
'',
(r'^admin/myapp/mymodel/$', my_model_list_view),
(r'^admin/myapp/mymodel/(\d+)/$', my_model_detail_view),
( r'^admin/', include( admin.site.urls ) )
)
You can add your views directly to the AdminSite object, rather than to any particular ModelAdmin subclass which you then register.
The default AdminSite is accessed via django.contrib.admin.site, which is what you call register and autodiscover on. Instead of using this, you could create your own subclass and add your own views to it, and then register your models against that rather than the default one.
The most straightforward answer is "no". As the Django Book says, the admin is for "Trusted users editing structured content," in this case the structured content being models arranged in hierarchies and configured through settings.py. More importantly, if your object doesn't completely duck-type to a models.Model complete with expected relationships, the admin will probably toss exceptions all over the place.
However, as the mantra goes, "It's just python." You can override any of the pages in admin. Just create your own templates in your project, and have them come first in the template search. Also, by inheriting admin/base.html, you maintain the look & feel of the administration project.
Write your administrative view and templates for this object, just like any others, but making sure to wrap the views in the is_staff decorator to ensure that the views are protected from access by unauthorized users. Put those in the application, perhaps in admin/views.py, with templates/admin/object_list.html and object_form.html.
Once you have appropriate administrative tools for these non-database objects, you can then provide access to them through the administration index page: You want to override admin/index.html, and provide additional project-specific items to the page as needed.
I have done exactly this to provide administrative access to third-party APIs that store our data, such as the ConstantContact email service, and it works pretty well.