I don't understand why Yii::getAlias( '#web' ) in my view file returns an empty string. #webroot returns the proper string.
Is there some configuration I'm missing?
#resting: Yii::getAlias( '#web' ) is Predefined Aliases in framework. No such kind of issue that will create. I thing issue is somewhere else.
Go through this link
Related
Suppose I have Session["myvalue"] which is integer.
Furthermore- I want to use this value in my HTML code (I want to display this value in the view).
Is there any way to do it?
If you are using MVC then you can go for #Session["myvalue"]
If you are using Asp.net then you can go for <%:Session["myvalue"].ToString()%>
To access session in View you can do following thing.
HttpContext.Current.Session["myvalue"].ToString()
if it is object or something then you have to case.
<<your type>> nameofVariable = (<<your type>>)HttpContext.Current.Session["myvalue"]
Apart from this you have to check null and everything.
This is the way
<%:Session["myvalue"]%>
If you get error then use
<%:Session["myvalue"].ToString()%>
just use an # symbol just in front of your session variable and you need to cust the session as an integer like
#(int)Session["myvalue"]
I am trying to save an Access query with the following statement.
INSERT INTO FOO( DES_MOTIVO, DES_TIPO, DES_SUBTIPO,
AGRUPACIÓN, SEMANA, CuentaDeCOD_ACCION_CLIENTE )
IN 'C:\Users\BAR\Desktop\03. Hola\DB STATIC INTERACCIONES MES.accdb'
I am getting an error when saving the query, saying the path is incorrect. Testing the path, i found out that the culprit is the period+whitespace in "03. Hola". Deleting the whitespace fixed the issue and the query saves properly.
Is there a way to escape the period so that access accepts the save path with period + whitespace?
Thank you in advance,
Nega.
Apparently this is not possible with SQL or VBA code.
Fun fact: You can do it in the query designer by setting the Destination database setting of the query properties. Set your path, the query can be saved and executed (and it works!).
But switch to SQL view and try to save: you get the "invalid bracketing" error. Same when trying to set the SQL from VBA.
And the DestinationDB property that the help file mentions isn't available via code. It seems to be derived from the IN clause.
So your database will have to moved to a better path. Or, if it's single user, copy to temp path, run the INSERT, copy back.
See also: https://support.microsoft.com/en-us/kb/132184
Try adding quotes around the path:
"INSERT INTO FOO( DES_MOTIVO, DES_TIPO, DES_SUBTIPO, AGRUPACIÓN, SEMANA, CuentaDeCOD_ACCION_CLIENTE ) IN '""C:\Users\BAR\Desktop\03. Hola\DB STATIC INTERACCIONES MES.accdb""'"
But why do you maintain such weird folder names as "03. Hola"?
Indeed on the Desktop, you should be able to create a simpler folder name.
I have to order a selection by CONVERT(`codExtern`, SIGNED) with codeIgniter.
If I use it like this:
$this->db->order_by(" CONVERT(`codExtern`, SIGNED) ");
the codeigniter puts the SIGNED word between `-s, like:
CONVERT(codExtern, `INTEGER` )
How can I make it work?
Unfortunately you can't disable identifier protection with parameters like in the select() method. CI will call CI_DB_driver::_protect_identifiers on the input if it has a , in it.
Currently you can workaround this if you set the supposedly "private" property $_protect_identifiers to false on your $this->db before calling the order_by method so when it runs it will skip this, and then flip it back (it helps with problematic column/table names for example). This is probably not a really good idea, in future CI versions this property might became really private and your code will break.
Unfortunately the database library cannot be extended, but if you are not afraid of modifying the files under system you can create an exception in the order_by() method just like the "order by random()" got one.
I'm trying to create a text file that contains the value of a custom field I added on redmine. I tried to get it from an SQL query in the create method of the project_controller.rb (at line 80 on redmine 1.2.0) as follows :
sql = Mysql.new('localhost','root','pass','bitnami_redmine')
rq = sql.query("SELECT value
FROM custom_values
INNER JOIN projects
ON custom_values.customized_id=projects.id
WHERE custom_values.custom_field_id=7
AND projects.name='#{#project.name}'")
rq.each_hash { |h|
File.open('pleasework.txt', 'w') { |myfile|
myfile.write(h['value'])
}
}
sql.close
This works fine if I test it in a separate file (with an existing project name instead of #project.name) so it may be a syntax issue but I can't find what it is. I'd also be glad to hear any other solution to get that value.
Thanks !
(there's a very similar post here but none of the solutions actually worked)
First, you could use Project.connection.query instead of your own Mysql instance. Second, I would try to log the SQL RAILS_DEFAULT_LOGGER.info "SELECT ..." and check if it's ok... And the third, I would use identifier instead of name.
I ended up simply using params["project"]["custom_field_values"]["x"] where x is the custom field's id. I still don't know why the sql query didn't work but well, this is much simpler and faster.
I have a 'user' table with a field name 'process_salary?' which has a boolean datatype
#user = User.create(params[:user])
if #user.process_salary?
//some code here
else
//some code here
end
When I create a new object of user and check for process_salary it gives me following error
NoMethodError: undefined method `process_salary?' for #<User:0xb6ac2f68>
Why does this error occur? Can I avoid it without changing my column name?
When I check it with the debugger it crashes the first time, but after that it runs properly
The question-mark has a special meaning in ActiveRecord. It can be used to check whether a field is true. You are using it as part of your field name which wasn't such a good idea. You could try if #user.process_salary?? exists but I think ultimately it is easiest to change your database column to be called 'process_salary'.
Side note: The 'rails console' is really helpful for playing around with models.
As cellcortex posted, question marks at the end of column names are tricky in Rails. If you need to have it there for legacy reasons, you might be able access the attribute as follows:
#user['process_salary?']
or the more verbose:
#user.read_attribute['process_salary?']
You can of course test for nil using .nil?.